xorp

update_attrib.hh

00001 // -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
00002 
00003 // Copyright (c) 2001-2011 XORP, Inc and Others
00004 //
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License, Version 2, June
00007 // 1991 as published by the Free Software Foundation. Redistribution
00008 // and/or modification of this program under the terms of any other
00009 // version of the GNU General Public License is not permitted.
00010 // 
00011 // This program is distributed in the hope that it will be useful, but
00012 // WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For more details,
00014 // see the GNU General Public License, Version 2, a copy of which can be
00015 // found in the XORP LICENSE.gpl file.
00016 // 
00017 // XORP Inc, 2953 Bunker Hill Lane, Suite 204, Santa Clara, CA 95054, USA;
00018 // http://xorp.net
00019 
00020 // $XORP: xorp/bgp/update_attrib.hh,v 1.16 2008/10/02 21:56:23 bms Exp $
00021 
00022 #ifndef __BGP_UPDATE_ATTRIB_HH__
00023 #define __BGP_UPDATE_ATTRIB_HH__
00024 
00025 #include "libxorp/ipvxnet.hh"
00026 #include "libxorp/exceptions.hh"
00027 #include "exceptions.hh"
00028 
00029 
00041 class BGPUpdateAttrib : public IPv4Net
00042 {
00043 public:
00047     BGPUpdateAttrib(const IPv4& d, uint8_t s) : IPv4Net(d, s) {}
00048 
00049     BGPUpdateAttrib(const IPv4Net& p) : IPv4Net(p)      {}
00050 
00051 #ifdef XORP_USE_USTL
00052     BGPUpdateAttrib() { }
00053 #endif
00054 
00058     BGPUpdateAttrib(const uint8_t *d);
00059 
00063     void copy_out(uint8_t *d) const;
00064 
00068     size_t wire_size() const                    {
00069     return calc_byte_size() + 1;
00070     }
00071 
00072     // size of next operand in memory
00073     static size_t size(const uint8_t *d) throw(CorruptMessage);
00074 
00075     size_t calc_byte_size() const           {
00076     return (prefix_len() + 7) / 8;
00077     }
00078 
00079     const IPv4Net& net() const              {
00080     return (IPv4Net &)(*this);
00081     }
00082 
00083     string str(string nlri_or_withdraw) const               {
00084     return nlri_or_withdraw + " " + net().str();
00085     }
00086 
00087 protected:
00088 private:
00089 };
00090 
00091 
00092 class BGPUpdateAttribList : public list <BGPUpdateAttrib> {
00093 public:
00094     typedef list <BGPUpdateAttrib>::const_iterator const_iterator;
00095     typedef list <BGPUpdateAttrib>::iterator iterator;
00096 
00097     size_t wire_size() const;
00098     uint8_t *encode(size_t &l, uint8_t *buf = 0) const;
00099     void decode(const uint8_t *d, size_t len)
00100     throw(CorruptMessage);
00101     string str(string) const;
00102 
00103     // XXX this needs to be fixed, we do not want to sort all the times.
00104     bool operator== (const BGPUpdateAttribList& other)  {
00105     if (size() != other.size())
00106         return false;
00107         BGPUpdateAttribList me(*this);
00108         BGPUpdateAttribList him(other);
00109     me.sort();
00110     him.sort();
00111     const_iterator i, j;
00112     // only check one iterator as we know length is the same
00113     for (i=me.begin(), j=him.begin(); i!=me.end(); ++i, ++j)
00114         if ( *i != *j )
00115         return false;
00116     return true;
00117     }
00118 };
00119 
00120 #endif // __BGP_UPDATE_ATTRIB_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations