Revision 1772a358

View differences:

include/AddressRange.h
128 128
    void to_xml(ostringstream &oss, const vector<int>& vms,
129 129
        const vector<int>& vnets, const vector<int>& vrs) const;
130 130

  
131
    /**
132
     *  Same as above but without the LEASES section
133
     */
134
    void to_xml(ostringstream &oss) const;
135

  
136

  
131 137
    // *************************************************************************
132 138
    // Address allocation functions
133 139
    // *************************************************************************
......
364 370
     */
365 371
    int from_attr(VectorAttribute * attr, string& error_msg);
366 372

  
373
    /**
374
     *  Builds an address request representation in XML form:
375
     *  <ADDRESS>
376
     *    <IP>
377
     *    <MAC>
378
     *    <IP6_ULA>
379
     *    <IP6_GLOBAL>
380
     *    <SIZE>
381
     */
382
    void addr_to_xml(unsigned int index, unsigned int size,
383
            ostringstream& oss) const;
384

  
367 385
    /* ---------------------------------------------------------------------- */
368 386
    /* Implementation specific address management interface                   */
369 387
    /* ---------------------------------------------------------------------- */
......
415 433
    /* ---------------------------------------------------------------------- */
416 434
    /* String to binary conversion functions for different address types      */
417 435
    /* ---------------------------------------------------------------------- */
418

  
419 436
    /**
420 437
     *  MAC to binary (48 bits)
421 438
     *    @param mac in string form 00:02:01:02:03:04
......
458 475
     * @param ip6_s Will contain the resulting IPv6 string
459 476
     * @return 0 on success
460 477
     */
461
    int ip6_to_s(const unsigned int prefix[], const unsigned int mac[], string& ip6_s) const;
478
    int ip6_to_s(const unsigned int prefix[], const unsigned int mac[],
479
        string& ip6_s) const;
462 480

  
463 481
    /* ---------------------------------------------------------------------- */
464 482
    /* NIC setup functions                                                    */
465 483
    /* ---------------------------------------------------------------------- */
466

  
467 484
    /**
468 485
     *  Check if the given MAC is valid for this address range by verifying:
469 486
     *    - Correct : notation
......
523 540
    /* ---------------------------------------------------------------------- */
524 541
    /* Address index map helper functions                                     */
525 542
    /* ---------------------------------------------------------------------- */
526

  
527 543
    /**
528 544
     *  This function generates a string representation of the in-memory allocated
529 545
     *  addresses. It'll be stored along side the AR vector attribute in the
include/AddressRangeIPAM.h
32 32
    virtual ~AddressRangeIPAM(){};
33 33

  
34 34
    /* ---------------------------------------------------------------------- */
35
    /* AddressRange Interface **TODO contact IPAM**                           */
35
    /* AddressRange Interface                                                 */
36 36
    /* ---------------------------------------------------------------------- */
37
    int from_vattr(VectorAttribute * attr, std::string& error_msg)
38
    {
39
        error_msg = "Not Implemented";
40
        return -1;
41
    };
42

  
43
    int allocate_addr(unsigned int index, unsigned int size, string& error_msg)
44
    {
45
        error_msg = "Not Implemented";
46
        return -1;
47
    };
48

  
49
    int get_addr(unsigned int& index, unsigned int rsize, string& error_msg)
50
    {
51
        error_msg = "Not Implemented";
52
        return -1;
53
    };
54

  
55
    int free_addr(unsigned int index, string& error_msg)
56
    {
57
        error_msg = "Not Implemented";
58
        return -1;
59
    };
37
    /**
38
     *  Init an Address Range based on a vector attribute.
39
     *    @param attr the description of the AddressRange
40
     *    @param error_msg description if error
41
     *    @return 0 on success
42
     */
43
    int from_vattr(VectorAttribute * attr, std::string& error_msg);
44

  
45
    /**
46
     *  Sets the given range of addresses (by index) as used
47
     *    @param index the first address to set as used
48
     *    @param sz number of addresses to set
49
     *    @param msg describing the error if any
50
     *
51
     *    @return 0 if success
52
     */
53
    int allocate_addr(unsigned int index, unsigned int rsize, string& error_msg);
54

  
55
    /**
56
     *  Gets a range of free addresses
57
     *    @param index the first address in the range
58
     *    @param size number of addresses requested in the range
59
     *    @param msg describing the error if any
60
     *
61
     *    @return 0 if success
62
     */
63
    int get_addr(unsigned int& index, unsigned int rsize, string& error_msg);
64

  
65
    /**
66
     *  Sets the given address (by index) as free
67
     *    @param index of the address
68
     *    @param msg describing the error if any
69
     *
70
     *    @return 0 if success
71
     */
72
    int free_addr(unsigned int index, string& msg);
60 73
};
61 74

  
62 75
#endif
include/AddressRangeInternal.h
34 34
    /* ---------------------------------------------------------------------- */
35 35
    /* AddressRange Interface                                                 */
36 36
    /* ---------------------------------------------------------------------- */
37

  
38 37
    /**
39 38
     *  Init an Address Range based on a vector attribute.
40 39
     *    @param attr the description of the AddressRange
......
54 53
     *
55 54
     *    @return 0 if success
56 55
     */
57
    int allocate_addr(unsigned int index, unsigned int size, string& error_msg)
56
    int allocate_addr(unsigned int index, unsigned int rsize, string& error_msg)
58 57
    {
59 58
        return 0;
60 59
    }
include/IPAMRequest.h
17 17
#ifndef IPAM_REQUEST_H_
18 18
#define IPAM_REQUEST_H_
19 19

  
20
#include <time.h>
21
#include <set>
22

  
23
#include "ActionManager.h"
24
#include "IPAMManager.h"
25
#include "NebulaUtil.h"
26

  
27 20
#include "SyncRequest.h"
28

  
29
using namespace std;
21
#include "NebulaUtil.h"
30 22

  
31 23
/**
32
 *  The IPAMRequest class is used to pass an Authorization or Authentication
24
 *  The IPAMRequest class represents a request for the IPAM driver. The request
25
 *  is in the form
33 26
 *  request to the AuthManager. The result of the request will be stored
34 27
 *  in the result and message attributes of this class.
35 28
 */
36 29
class IPAMRequest : public SyncRequest
37 30
{
38 31
public:
39
    IPAMRequest(string _params): params(_params){};
32
    /* ---------------------------------------------------------------------- */
33
    /* IPAM Request constructors                                              */
34
    /* ---------------------------------------------------------------------- */
35
    IPAMRequest(const std::string& _ar_xml) :
36
        ar_xml(_ar_xml), address_xml("<ADDRESS></MAC></IP></IP6_GLOBAL>"
37
                "</IP6_ULA></SIZE></ADDRESS>"){};
40 38

  
41
    ~IPAMRequest(){};
39
    IPAMRequest(const std::string& _ar_xml, const std::string& _address_xml) :
40
        ar_xml(_ar_xml), address_xml(_address_xml){};
42 41

  
43
private:
42
    virtual ~IPAMRequest(){};
43

  
44
    /* ---------------------------------------------------------------------- */
45
    /* Driver message formatting and processing                               */
46
    /* ---------------------------------------------------------------------- */
47
    std::string& to_xml64(std::string& action_data) const
48
    {
49
        std::ostringstream oss;
50
        std::string * aux_str;
44 51

  
45
    friend class IPAMManager;
52
        oss << "<IPAM_DRIVER_ACTION_DATA>"
53
            << ar_xml
54
            << address_xml
55
            << "</IPAM_DRIVER_ACTION_DATA>";
46 56

  
57
        aux_str     = one_util::base64_encode(oss.str());
58
        action_data = *aux_str;
59

  
60
        free(aux_str);
61

  
62
        return action_data;
63
    }
64

  
65
private:
47 66
    /**
48
     *  The params for this request
67
     *  XML representation for this request <AR>...</AR>
49 68
     */
50
    string    params;
69
    string ar_xml;
51 70

  
71
    /**
72
     * Address request representation
73
     */
74
    string address_xml;
52 75
};
53 76

  
54 77
#endif
include/Nebula.h
49 49
#include "AclManager.h"
50 50
#include "ImageManager.h"
51 51
#include "MarketPlaceManager.h"
52
#include "IPAMManager.h"
52 53

  
53 54
#include "DefaultQuotas.h"
54 55

  
......
209 210
        return marketm;
210 211
    };
211 212

  
213
    IPAMManager * get_ipamm()
214
    {
215
        return ipamm;
216
    };
217

  
212 218
    // --------------------------------------------------------------
213 219
    // Environment & Configuration
214 220
    // --------------------------------------------------------------
......
580 586
        dspool(0), clpool(0), docpool(0), zonepool(0),
581 587
        secgrouppool(0), vdcpool(0), vrouterpool(0), marketpool(0), apppool(0),
582 588
        lcm(0), vmm(0), im(0), tm(0), dm(0), rm(0), hm(0), authm(0),
583
        aclm(0), imagem(0), marketm(0)
589
        aclm(0), imagem(0), marketm(0), ipamm(0)
584 590
    {
585 591
        const char * nl = getenv("ONE_LOCATION");
586 592

  
......
642 648
        delete aclm;
643 649
        delete imagem;
644 650
        delete marketm;
651
        delete ipamm;
645 652
        delete nebula_configuration;
646 653
        delete db;
647 654
        delete system_db;
......
730 737
    AclManager *            aclm;
731 738
    ImageManager *          imagem;
732 739
    MarketPlaceManager *    marketm;
740
    IPAMManager *           ipamm;
733 741

  
734 742
    // ---------------------------------------------------------------
735 743
    // Implementation functions
src/ipamm/IPAMManager.cc
174 174

  
175 175
void IPAMManager::register_address_range_action(IPAMRequest * ir)
176 176
{
177
    std::string action_data;
177 178
    const IPAMManagerDriver * ipammd = setup_request(ir);
178 179

  
179 180
    if (ipammd == 0)
......
181 182
        return;
182 183
    }
183 184

  
184
    ipammd->register_address_range(ir->id, ir->params);
185
    ipammd->register_address_range(ir->id, ir->to_xml64(action_data));
185 186
}
186 187

  
187 188
/* -------------------------------------------------------------------------- */
188 189

  
189 190
void IPAMManager::get_address_action(IPAMRequest * ir)
190 191
{
192
    std::string action_data;
191 193
    const IPAMManagerDriver * ipammd = setup_request(ir);
192 194

  
193 195
    if (ipammd == 0)
......
195 197
        return;
196 198
    }
197 199

  
198
    ipammd->get_address(ir->id, ir->params);
200
    ipammd->get_address(ir->id, ir->to_xml64(action_data));
199 201
}
200 202

  
201 203
/* -------------------------------------------------------------------------- */
202 204

  
203 205
void IPAMManager::allocate_address_action(IPAMRequest * ir)
204 206
{
207
    std::string action_data;
205 208
    const IPAMManagerDriver * ipammd = setup_request(ir);
206 209

  
207 210
    if (ipammd == 0)
......
209 212
        return;
210 213
    }
211 214

  
212
    ipammd->allocate_address(ir->id, ir->params);
215
    ipammd->allocate_address(ir->id, ir->to_xml64(action_data));
213 216
}
214 217

  
215 218
/* -------------------------------------------------------------------------- */
216 219

  
217 220
void IPAMManager::free_address_action(IPAMRequest * ir)
218 221
{
222
    std::string action_data;
219 223
    const IPAMManagerDriver * ipammd = setup_request(ir);
220 224

  
221 225
    if (ipammd == 0)
......
223 227
        return;
224 228
    }
225 229

  
226
    ipammd->free_address(ir->id, ir->params);
230
    ipammd->free_address(ir->id, ir->to_xml64(action_data));
227 231
}
228 232

  
229 233
/* ************************************************************************** */
src/nebula/SConstruct
66 66
    'nebula_vdc',
67 67
    'nebula_vrouter',
68 68
    'nebula_marketplace',
69
    'nebula_ipamm',
69 70
    'crypto',
70 71
    'xml2'
71 72
])
src/vnm/AddressRange.cc
388 388
/* -------------------------------------------------------------------------- */
389 389
/* -------------------------------------------------------------------------- */
390 390

  
391
void AddressRange::addr_to_xml(unsigned int index, unsigned int rsize,
392
        ostringstream& oss) const
393
{
394
    unsigned int new_mac[2];
395
    string       ip6_s;
396

  
397
    new_mac[0] = mac[0] + index;
398
    new_mac[1] = mac[1];
399

  
400
    oss << "<ADDRESS>"
401
        << "<MAC>" << mac_to_s(new_mac) << "</MAC>";
402

  
403
    if ( ip != 0 )
404
    {
405
        oss << "<IP>" << ip_to_s(ip + index) << "</IP>";
406
    }
407

  
408
    if (ula6[1] != 0 || ula6[0] != 0 )
409
    {
410
        oss << "<IP6_ULA>" << ip6_to_s(ula6, new_mac, ip6_s) << "</IP6_ULA>";
411
    }
412

  
413
    if (global6[1] != 0 || global6[0] != 0)
414
    {
415
        oss << "<IP6_GLOBAL>" << ip6_to_s(global6, new_mac, ip6_s)
416
            << "</IP6_GLOBAL>";
417
    }
418

  
419
    oss << "<SIZE>" << rsize << "</SIZE>"
420
        << "</ADDRESS>";
421
}
422

  
423
/* -------------------------------------------------------------------------- */
424
/* -------------------------------------------------------------------------- */
425

  
426
void AddressRange::to_xml(ostringstream &oss) const
427
{
428
    const map<string,string>& ar_attrs = attr->value();
429
    map<string,string>::const_iterator it;
430

  
431
    string       aux_st;
432
    unsigned int mac_end[2];
433

  
434
    oss << "<AR>";
435

  
436
    for (it=ar_attrs.begin(); it != ar_attrs.end(); it++)
437
    {
438
        if ( it->first == "ALLOCATED" )
439
        {
440
            continue;
441
        }
442

  
443
        oss << "<" << it->first << ">"
444
            << one_util::escape_xml(it->second)
445
            << "</"<< it->first << ">";
446
    }
447

  
448
    mac_end[1] = mac[1];
449
    mac_end[0] = (mac[0] + size - 1);
450

  
451
    oss << "<MAC_END>" << one_util::escape_xml(mac_to_s(mac_end))<<"</MAC_END>";
452

  
453
    aux_st = attr->vector_value("IP");
454

  
455
    if (aux_st != "")
456
    {
457
        unsigned int ip_i;
458

  
459
        if (ip_to_i(aux_st, ip_i) == 0)
460
        {
461
            oss << "<IP_END>" << one_util::escape_xml(ip_to_s(ip_i + size - 1))
462
                << "</IP_END>";
463
        }
464
    }
465

  
466
    if (type & 0x00000004)
467
    {
468
        string ip6_s;
469

  
470
        if (ula6[1] != 0 || ula6[0] != 0 )
471
        {
472
            ip6_to_s(ula6, mac, ip6_s);
473
            oss << "<IP6_ULA>" << one_util::escape_xml(ip6_s) << "</IP6_ULA>";
474

  
475
            ip6_to_s(ula6, mac_end, ip6_s);
476
            oss << "<IP6_ULA_END>" << one_util::escape_xml(ip6_s)
477
                << "</IP6_ULA_END>";
478
        }
479

  
480
        if (global6[1] != 0 || global6[0] != 0 )
481
        {
482
            ip6_to_s(global6, mac, ip6_s);
483
            oss << "<IP6_GLOBAL>" << one_util::escape_xml(ip6_s)
484
                << "</IP6_GLOBAL>";
485

  
486
            ip6_to_s(global6, mac_end, ip6_s);
487
            oss << "<IP6_GLOBAL_END>" << one_util::escape_xml(ip6_s)
488
                << "</IP6_GLOBAL_END>";
489
        }
490
    }
491

  
492
    oss << "<USED_LEASES>" << get_used_addr() << "</USED_LEASES>";
493
    oss << "</AR>";
494
}
495

  
496
/* -------------------------------------------------------------------------- */
497
/* -------------------------------------------------------------------------- */
498

  
391 499
void AddressRange::to_xml(ostringstream &oss, const vector<int>& vms,
392 500
        const vector<int>& vns, const vector<int>& vrs) const
393 501
{
src/vnm/AddressRangeIPAM.cc
1
/* -------------------------------------------------------------------------- */
2
/* Copyright 2002-2016, OpenNebula Project, OpenNebula Systems                */
3
/*                                                                            */
4
/* Licensed under the Apache License, Version 2.0 (the "License"); you may    */
5
/* not use this file except in compliance with the License. You may obtain    */
6
/* a copy of the License at                                                   */
7
/*                                                                            */
8
/* http://www.apache.org/licenses/LICENSE-2.0                                 */
9
/*                                                                            */
10
/* Unless required by applicable law or agreed to in writing, software        */
11
/* distributed under the License is distributed on an "AS IS" BASIS,          */
12
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   */
13
/* See the License for the specific language governing permissions and        */
14
/* limitations under the License.                                             */
15
/* -------------------------------------------------------------------------- */
16

  
17
#include "AddressRangeIPAM.h"
18
#include "IPAMRequest.h"
19
#include "IPAMManager.h"
20

  
21
#include "Nebula.h"
22
#include "NebulaUtil.h"
23

  
24
/* ************************************************************************** */
25
/* ************************************************************************** */
26

  
27
int AddressRangeIPAM::from_vattr(VectorAttribute * attr, std::string& error_msg)
28
{
29
    IPAMManager * ipamm = Nebula::instance().get_ipamm();
30
    std::string * ar_xml= attr->to_xml();
31

  
32
    IPAMRequest ir(*ar_xml);
33

  
34
    free(ar_xml);
35

  
36
    ipamm->trigger(IPAMManager::REGISTER_ADDRESS_RANGE, &ir);
37

  
38
    ir.wait();
39

  
40
    if (ir.result != true)
41
    {
42
        error_msg = ir.message;
43
        return -1;
44
    }
45

  
46
    //attr <----> from ir.message
47
    return AddressRange::from_attr(attr, error_msg);
48
}
49

  
50
int AddressRangeIPAM::allocate_addr(unsigned int index, unsigned int rsize,
51
    std::string& error_msg)
52
{
53
    IPAMManager *      ipamm = Nebula::instance().get_ipamm();
54
    std::ostringstream oss;
55

  
56
    std::string ar_xml;
57
    std::string address_xml;
58

  
59
    to_xml(oss);
60

  
61
    ar_xml = oss.str();
62

  
63
    oss.str("");
64

  
65
    addr_to_xml(index, rsize, oss);
66

  
67
    address_xml = oss.str();
68

  
69
    IPAMRequest ir(ar_xml, address_xml);
70

  
71
    ipamm->trigger(IPAMManager::ALLOCATE_ADDRESS, &ir);
72

  
73
    ir.wait();
74

  
75
    if (ir.result != true)
76
    {
77
        error_msg = ir.message;
78
        return -1;
79
    }
80

  
81
    return 0;
82
}
83

  
84
int AddressRangeIPAM::get_addr(unsigned int& index, unsigned int rsize,
85
    std::string& error_msg)
86
{
87
    IPAMManager *      ipamm = Nebula::instance().get_ipamm();
88
    std::ostringstream oss;
89

  
90
    std::string ar_xml;
91
    std::string address_xml;
92

  
93
    to_xml(oss);
94

  
95
    ar_xml = oss.str();
96

  
97
    oss.str("");
98

  
99
    addr_to_xml(index, rsize, oss);
100

  
101
    address_xml = oss.str();
102

  
103
    IPAMRequest ir(ar_xml, address_xml);
104

  
105
    ipamm->trigger(IPAMManager::GET_ADDRESS, &ir);
106

  
107
    ir.wait();
108

  
109
    if (ir.result != true)
110
    {
111
        error_msg = ir.message;
112
        return -1;
113
    }
114

  
115
    //index <----> from ir.message
116
    return 0;
117
}
118

  
119
int AddressRangeIPAM::free_addr(unsigned int index, std::string& error_msg)
120
{
121
    IPAMManager *      ipamm = Nebula::instance().get_ipamm();
122
    std::ostringstream oss;
123

  
124
    std::string ar_xml;
125
    std::string address_xml;
126

  
127
    to_xml(oss);
128

  
129
    ar_xml = oss.str();
130

  
131
    oss.str("");
132

  
133
    addr_to_xml(index, 1, oss);
134

  
135
    address_xml = oss.str();
136

  
137
    IPAMRequest ir(ar_xml, address_xml);
138

  
139
    ipamm->trigger(IPAMManager::FREE_ADDRESS, &ir);
140

  
141
    ir.wait();
142

  
143
    if (ir.result != true)
144
    {
145
        error_msg = ir.message;
146
        return -1;
147
    }
148

  
149
    return 0;
150
}
151

  
src/vnm/SConstruct
26 26
    'VirtualNetworkPool.cc',
27 27
    'AddressRange.cc',
28 28
    'AddressRangeInternal.cc',
29
    'AddressRangeIPAM.cc',
29 30
    'AddressRangePool.cc',
30 31
    'VirtualNetworkTemplate.cc'
31 32
]

Also available in: Unified diff