~ubuntu-branches/ubuntu/jaunty/xorp/jaunty

« back to all changes in this revision

Viewing changes to bgp/aspath.hh

  • Committer: Bazaar Package Importer
  • Author(s): Jose Calhariz, Javier Fernandez-Sanguino, Jose Calhariz
  • Date: 2008-01-23 01:24:37 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080123012437-7l2u9r0k8e7op8st
Tags: 1.5~cvs.20080128-1
[ Javier Fernandez-Sanguino ]
* Update to latest CVS contents
* Modify debian/rules to prevent autobuilders from building 
  the binary-independent components: (Closes: #441121)
  - Create a new Build-Depends-Indep with all the TeX
  components used to build documentation
  - Since autobuilders call build, which in turns calls build-indep, hack
    the debian rules file so that the documentation is only built if ps2pdf,
    dvips and pslatex are available. 
* Modify the init.d script:
  - restart action: Do not attempt to stop xorp if not running
  - stop function: fix errors in the script
  - add a try-restart action
  - restructure the init.d script, move the restart code to a function
  - review the use of echo calls and exit values
* Use, as examples, the new boot files at rtrmgr/config/

[ Jose Calhariz ]
* Add depends on ncurses-dev, I don't know why xorp use tigetstr
  function from curses.  This way the depends field change less between
  build environments.
* Removed pushd and popd commands from Makefile and replaced with cd
  commands, was a bashism and FTBFS (closes: #453637)
* debian/control converted to utf-8 (closes: #454026) (closes: #453485)
* init.d/xorp now returns 0 if disabled.
* Added Vcs-Browser and Vcs-Svn fields pointing to the repository of the
  package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
2
2
 
3
 
// Copyright (c) 2001-2007 International Computer Science Institute
 
3
// Copyright (c) 2001-2008 International Computer Science Institute
4
4
//
5
5
// Permission is hereby granted, free of charge, to any person obtaining a
6
6
// copy of this software and associated documentation files (the "Software")
12
12
// notice is a summary of the XORP LICENSE file; the license in that file is
13
13
// legally binding.
14
14
 
15
 
// $XORP: xorp/bgp/aspath.hh,v 1.29 2007/04/05 02:02:48 zec Exp $
 
15
// $XORP: xorp/bgp/aspath.hh,v 1.31 2008/01/04 03:15:17 pavlin Exp $
16
16
 
17
17
#ifndef __BGP_ASPATH_HH__
18
18
#define __BGP_ASPATH_HH__
30
30
#include "libxorp/exceptions.hh"
31
31
#include "exceptions.hh"
32
32
 
 
33
class AS4Path;
 
34
 
33
35
/**
34
36
 * This file contains the classes to manipulate AS segments/lists/paths
35
37
 *
64
66
 * AS_CONFED_SET: unordered set of Member AS Numbers in
65
67
 * the local confederation that the UPDATE message has traversed
66
68
 *  
 
69
 *
 
70
 * 4-byte AS numbers need to be handled carefully.  There are two main
 
71
 * cases to consider: when we are configured to do 4-byte AS numbers,
 
72
 * and when we are not.
 
73
 *
 
74
 * When we are not configured to do 4-byte AS numbers all AS path
 
75
 * information received from peers will be 2-byte AS numbers.  If
 
76
 * they're configured to do 4-byte AS numbers, they will send us an
 
77
 * AS_PATH and an AS4_PATH, but if we're not configured to do 4-byte
 
78
 * AS numbers, we shouldn't care.  We don't merge the two; we
 
79
 * propagate AS4_PATH unchanged, and do the normal stuff with the
 
80
 * regular AS_PATH.  The AS4_PATH is actually stored internally in an
 
81
 * UnknownAttribute, as we don't need to know anything about it.
 
82
 *
 
83
 * When we are configured to do 4-byte AS numbers, we can tell from
 
84
 * the negotiated capabilities whether a peer is sending 4-byte AS
 
85
 * numbers or 2-byte AS numbers.  If a peer is sending 4-byte AS
 
86
 * numbers, these arrive in the AS_PATH attribute, and we store them
 
87
 * internally in an AS4Path, but stored in the ASPathAttribute, NOT in
 
88
 * the AS4PathAttribute.  If a peer is sending 2-byte AS numbers in
 
89
 * AS_PATH, he may also propagate an AS4_PATH.  We merge these on
 
90
 * input, cross-validate the two, and store the results just like we
 
91
 * would if we'd received a 4-byte AS_PATH.  So, whatever our peer
 
92
 * does, the only place we have AS path information that we use for
 
93
 * the decision process is in the ASPathAttribute.
 
94
 *
 
95
 * If we're doing 4-byte AS numbers and our peer is doing 4-byte AS
 
96
 * numbers, then all routes we send him will contain 4-byte AS_PATH
 
97
 * attributes.  We just need to make sure we use the right encode()
 
98
 * method.  If our peer is not doing 4-byte AS numbers, then we send a
 
99
 * 2-byte AS_PATH, substituting AS_TRANS for any AS numbers that can't
 
100
 * be represented in 2 bytes.  We also construct an AS4_PATH from our
 
101
 * ASPathAttribute, and send that too.
67
102
 */
68
103
 
69
104
// AS Path Values
76
111
};
77
112
 
78
113
/**
79
 
 * Parent class for AsPath elements, which can be either AsSet or AsSequence.
 
114
 * Parent class for ASPath elements, which can be either ASSet or ASSequence.
80
115
 */
81
 
class AsSegment {
 
116
class ASSegment {
82
117
public:
83
118
    typedef vector <AsNum>::iterator iterator;
84
119
    typedef vector <AsNum>::const_iterator const_iterator;
85
120
    typedef vector <AsNum>::const_reverse_iterator const_reverse_iterator;
86
121
 
87
122
    /**
88
 
     * Constructor of an empty AsSegment
 
123
     * Constructor of an empty ASSegment
89
124
     */
90
 
    AsSegment(ASPathSegType t = AS_NONE) : _type(t)     {
 
125
    ASSegment(ASPathSegType t = AS_NONE) : _type(t)     {
91
126
        _aslist.reserve(16);
92
127
    }
93
128
 
98
133
     *
99
134
     * _type is d[0], l is d[1], entries follow.
100
135
     */
101
 
    AsSegment(const uint8_t* d) throw(CorruptMessage)   {
 
136
    ASSegment(const uint8_t* d) throw(CorruptMessage)   {
102
137
        _aslist.reserve(16);
103
138
        decode(d);
104
139
    }
106
141
    /**
107
142
     * Copy constructor
108
143
     */
109
 
    AsSegment(const AsSegment& a) :
 
144
    ASSegment(const ASSegment& a) :
110
145
        _type(a._type), _aslist(a._aslist)              {}
111
146
 
112
147
    /**
113
148
     * The destructor has nothing to do, the underlying container will
114
149
     * take care of the thing.
115
150
     */
116
 
    ~AsSegment()                                        {}
 
151
    ~ASSegment()                                        {}
117
152
 
118
153
    /**
119
154
     * reset whatever is currently contained in the object.
216
251
    /**
217
252
     * compares internal representations for equality.
218
253
     */
219
 
    bool operator==(const AsSegment& him) const;
 
254
    bool operator==(const ASSegment& him) const;
220
255
 
221
256
    /**
222
257
     * Compares internal representations for <.
223
258
     */
224
 
    bool operator<(const AsSegment& him) const;
 
259
    bool operator<(const ASSegment& him) const;
225
260
 
226
261
    ASPathSegType type() const                  { return _type; }
227
262
    void set_type(ASPathSegType t)              { _type = t; }
240
275
};
241
276
 
242
277
 
243
 
/* subsclass of AsSegment to handle encoding and decoding of 4-byte AS
 
278
/* subsclass of ASSegment to handle encoding and decoding of 4-byte AS
244
279
   numbers from a AS4_PATH attribute */
245
 
class As4Segment : public AsSegment {
 
280
class AS4Segment : public ASSegment {
246
281
public:
247
 
    As4Segment(const uint8_t* d) throw(CorruptMessage) { decode(d); }
 
282
    AS4Segment(const uint8_t* d) throw(CorruptMessage) { decode(d); }
248
283
    /**
249
284
     * Convert the external representation into the internal one.
250
285
     * _type is d[0], _entries is d[1], entries follow.
267
302
        return 2 + 4 * _aslist.size();
268
303
    }
269
304
private:
270
 
    /* no storage, as this is handled by the underlying AsSegment */
 
305
    /* no storage, as this is handled by the underlying ASSegment */
271
306
};
272
307
 
273
308
/**
274
 
 * An AsPath is a list of AsSegments, each of which can be an AS_SET,
 
309
 * An ASPath is a list of ASSegments, each of which can be an AS_SET,
275
310
 * AS_CONFED_SET, AS_SEQUENCE, or an AS_CONFED_SEQUENCE.
276
311
 */
277
 
class AsPath {
 
312
class ASPath {
278
313
public:
279
 
    typedef list <AsSegment>::const_iterator const_iterator;
280
 
    typedef list <AsSegment>::iterator iterator;
 
314
    typedef list <ASSegment>::const_iterator const_iterator;
 
315
    typedef list <ASSegment>::iterator iterator;
281
316
 
282
 
    AsPath() : _num_segments(0), _path_len(0)           {}
 
317
    ASPath() : _num_segments(0), _path_len(0)           {}
283
318
 
284
319
    /**
285
320
     * Initialize from a string in the format
286
321
     *          1,2,(3,4,5),6,7,8,(9,10,11),12,13
287
322
     */
288
 
    AsPath(const char *as_path) throw(InvalidString);
 
323
    ASPath(const char *as_path) throw(InvalidString);
289
324
 
290
325
    /**
291
326
     * construct from received data
292
327
     */
293
 
    AsPath(const uint8_t* d, size_t len) throw(CorruptMessage) {
 
328
    ASPath(const uint8_t* d, size_t len) throw(CorruptMessage) {
294
329
        decode(d, len); 
295
330
    }
296
331
 
297
332
    /**
298
 
     * construct an aggregate from two AsPaths
 
333
     * construct an aggregate from two ASPaths
299
334
     */
300
 
    AsPath(const AsPath &asp1, const AsPath &asp2);
 
335
    ASPath(const ASPath &asp1, const ASPath &asp2);
301
336
 
302
337
    /**
303
338
     * Copy constructor
304
339
     */
305
 
    AsPath(const AsPath &a) : _segments(a._segments), 
 
340
    ASPath(const ASPath &a) : _segments(a._segments), 
306
341
        _num_segments(a._num_segments), _path_len(a._path_len) {}
307
342
 
308
 
    ~AsPath()                                           {}
 
343
    ~ASPath()                                           {}
309
344
 
310
 
    void add_segment(const AsSegment& s);
311
 
    void prepend_segment(const AsSegment& s);
 
345
    void add_segment(const ASSegment& s);
 
346
    void prepend_segment(const ASSegment& s);
312
347
 
313
348
    size_t path_length() const                          { return _path_len; }
314
349
 
328
363
    string str() const;
329
364
    string short_str() const;
330
365
 
331
 
    const AsSegment& segment(size_t n) const            {
 
366
    const ASSegment& segment(size_t n) const            {
332
367
        if (n < _num_segments) {
333
368
            const_iterator iter = _segments.begin();
334
369
            for (u_int i = 0; i<n; i++)
335
370
                ++iter;
336
371
            return (*iter);
337
372
        }
338
 
        XLOG_FATAL("Segment doesn't exist.");
 
373
        XLOG_FATAL("Segment %u doesn't exist.", (uint32_t)n);
339
374
        xorp_throw(InvalidString, "segment invalid n\n");
340
375
    }
341
376
 
362
397
 
363
398
    /**
364
399
     * Add the As number to the begining of the AS_SEQUENCE that starts
365
 
     * the As path, or if the AsPath starts with an AS_SET, then add a
366
 
     * new AS_SEQUENCE with the new AsNum to the start of the AsPath
 
400
     * the As path, or if the ASPath starts with an AS_SET, then add a
 
401
     * new AS_SEQUENCE with the new AsNum to the start of the ASPath
367
402
     */
368
403
    void prepend_as(const AsNum &asn);
369
404
 
370
405
    /**
371
406
     * Add the As number to the begining of the AS_CONFED_SEQUENCE
372
 
     * that starts the As path, or if the AsPath does not start with
 
407
     * that starts the As path, or if the ASPath does not start with
373
408
     * an AS_CONFED_SEQUENCE, then add a new AS_CONFED_SEQUENCE with
374
 
     * the new AsNum to the start of the AsPath
 
409
     * the new AsNum to the start of the ASPath
375
410
     */
376
411
    void prepend_confed_as(const AsNum &asn);
377
412
 
385
420
     */
386
421
    bool contains_confed_segments() const;
387
422
 
388
 
    bool operator==(const AsPath& him) const;
389
 
 
390
 
    bool operator<(const AsPath& him) const;
 
423
    ASPath& operator=(const ASPath& him);
 
424
 
 
425
    bool operator==(const ASPath& him) const;
 
426
 
 
427
    bool operator<(const ASPath& him) const;
391
428
 
392
429
    void encode_for_mib(vector<uint8_t>& aspath) const;
393
430
 
396
433
     * represented entirely as two-byte AS numbers */
397
434
    bool two_byte_compatible() const;
398
435
 
 
436
    /**
 
437
     * Merge an AS4Path into a 2-byte AS Path.  Both paths will end up
 
438
     * containing the same data
 
439
     *
 
440
     * param as4path the AS4_PATH to be merged.  
 
441
     */
 
442
    void merge_as4_path(AS4Path& as4_path);
 
443
 
399
444
protected:
400
445
    /**
401
446
     * internal representation
402
447
     */
403
 
    list <AsSegment>    _segments;
 
448
    list <ASSegment>    _segments;
404
449
    size_t              _num_segments;
405
450
    size_t              _path_len;
406
451
 
407
452
private:
408
453
    /**
409
 
     * populate an AsPath from received data. Only used in the constructor.
 
454
     * populate an ASPath from received data. Only used in the constructor.
410
455
     */
411
456
    void decode(const uint8_t *d, size_t len) throw(CorruptMessage);
412
457
};
413
458
 
414
459
/* subclass to handle 4-byte AS encoding and decoding */
415
 
class As4Path : public AsPath {
 
460
class AS4Path : public ASPath {
416
461
public:
417
462
    /**
418
 
     * construct from received data.  This needs to take the regular
419
 
     * AsPath in addition to the AS4_PATH data, because it needs to
420
 
     * cross-validate the two.
421
 
     */
422
 
    As4Path(const uint8_t* d, size_t len, const AsPath& as_path)
 
463
     * Construct from received data from 4-byte peer.
 
464
     */
 
465
    AS4Path(const uint8_t* d, size_t len) throw(CorruptMessage);
 
466
 
 
467
    /**
 
468
     * Initialize from a string in the format
 
469
     *          3.1,2,(3,10.4,5),6,7,8,(9,10,11),12,13
 
470
     */
 
471
    AS4Path(const char *as_path) throw(InvalidString) 
 
472
        : ASPath(as_path)
 
473
    {};
 
474
 
 
475
#if 0
 
476
    /**
 
477
     * Construct from received data from 2-byte peer.  This needs to
 
478
     * take the regular ASPath in addition to the AS4_PATH data,
 
479
     * because it needs to cross-validate the two.
 
480
     */
 
481
    AS4Path(const uint8_t* d, size_t len, const ASPath& as_path)
423
482
        throw(CorruptMessage);
424
483
 
 
484
#endif
 
485
 
425
486
    /**
426
487
     * Convert from internal to external representation, with the
427
488
     * correct representation for the original AS4_PATH attribute.
435
496
 
436
497
    size_t wire_size() const;
437
498
 
 
499
    void cross_validate(const ASPath& as_path);
 
500
 
438
501
private:
439
502
    /**
440
 
     * populate an AsPath from received data. Only used in the constructor.
 
503
     * populate an ASPath from received data. Only used in the constructor.
441
504
     */
442
505
    void decode(const uint8_t *d, size_t len) throw(CorruptMessage);
443
 
    void cross_validate(const AsPath& as_path);
444
 
    void pad_segment(const AsSegment& old_seg, AsSegment& new_seg);
445
 
    void do_patchup(const AsPath& as_path);
 
506
    void pad_segment(const ASSegment& old_seg, ASSegment& new_seg);
 
507
    void do_patchup(const ASPath& as_path);
446
508
};
447
509
 
448
510
#endif // __BGP_ASPATH_HH__