Skip to content

Commit

Permalink
Remove exceptions from ospf
Browse files Browse the repository at this point in the history
More to go

Signed-off-by: Ben Greear <greearb@candelatech.com>
  • Loading branch information
greearb committed Sep 16, 2017
1 parent 4e727b7 commit 1dd2c2b
Show file tree
Hide file tree
Showing 10 changed files with 934 additions and 783 deletions.
920 changes: 512 additions & 408 deletions xorp/ospf/lsa.cc

Large diffs are not rendered by default.

86 changes: 53 additions & 33 deletions xorp/ospf/lsa.hh
Expand Up @@ -17,7 +17,6 @@
// XORP Inc, 2953 Bunker Hill Lane, Suite 204, Santa Clara, CA 95054, USA;
// http://xorp.net

// $XORP: xorp/ospf/lsa.hh,v 1.113 2008/10/02 21:57:47 bms Exp $

#ifndef __OSPF_LSA_HH__
#define __OSPF_LSA_HH__
Expand All @@ -26,7 +25,7 @@
* LSA Header. Common header for all LSAs.
* Never store or pass a pointer, just deal with it inline.
*/
class Lsa_header {
class Lsa_header : public Invalid {
public:
Lsa_header(OspfTypes::Version version) :
_version(version), _LS_age(0), _options(0), _ls_type(0),
Expand All @@ -35,7 +34,7 @@ class Lsa_header {
_ls_checksum(0), _length(0)
{}

Lsa_header(const Lsa_header& rhs) {
Lsa_header(const Lsa_header& rhs) : Invalid(rhs) {
copy(rhs);
}

Expand All @@ -58,6 +57,7 @@ class Lsa_header {
lsa_copy(_ls_sequence_number);
lsa_copy(_ls_checksum);
lsa_copy(_length);
set_invalid(rhs.invalid());
}
#undef lsa_copy

Expand All @@ -74,12 +74,12 @@ class Lsa_header {
/**
* Decode a LSA header and return a LSA header inline not a pointer.
*/
Lsa_header decode(uint8_t *ptr) const throw(InvalidPacket);
Lsa_header decode(uint8_t *ptr, string& err);

/**
* Decode this lsa header in this context.
*/
void decode_inline(uint8_t *ptr) throw(InvalidPacket);
bool decode_inline(uint8_t *ptr, string& err);

/**
* Copy a wire format representation to the pointer provided.
Expand Down Expand Up @@ -181,7 +181,7 @@ class Lsa_header {
string str() const;

private:
void decode(Lsa_header& header, uint8_t *ptr) const throw(InvalidPacket);
bool decode(Lsa_header& header, uint8_t *ptr, string& err) const;

OspfTypes::Version _version;
uint16_t _LS_age;
Expand Down Expand Up @@ -262,7 +262,7 @@ compare_all_header_fields(const Lsa_header& lhs, const Lsa_header& rhs)
*
* A generic LSA. All actual LSAs should be derived from this LSA.
*/
class Lsa {
class Lsa : public Invalid {
public:
/**
* A reference counted pointer to an LSA which will be
Expand Down Expand Up @@ -339,8 +339,7 @@ class Lsa {
*
* @return A reference to an LSA that manages its own memory.
*/
virtual LsaRef decode(uint8_t *buf, size_t& len) const
throw(InvalidPacket) = 0;
virtual LsaRef decode(uint8_t *buf, size_t& len, string& err) const = 0;

/**
* Encode an LSA for transmission.
Expand Down Expand Up @@ -606,6 +605,10 @@ class Lsa {
*/
virtual string str() const = 0;

virtual bool invalid() const {
return (Invalid::invalid() || _header.invalid());
}

/**
* Add the LSA type bindings.
*/
Expand Down Expand Up @@ -695,7 +698,7 @@ class LsaDecoder {
*
* @return A reference to an LSA that manages its own memory.
*/
Lsa::LsaRef decode(uint8_t *ptr, size_t& len) const throw(InvalidPacket);
Lsa::LsaRef decode(uint8_t *ptr, size_t& len, string& err) const;

/**
* @return The length of the smallest LSA that can be decoded.
Expand Down Expand Up @@ -753,7 +756,7 @@ class LsaDecoder {
* RFC 2470 A.4.1 IPv6 Prefix Representation
* OSPFv3 only
*/
class IPv6Prefix {
class IPv6Prefix : public Invalid {
public:
static const uint8_t NU_bit = 0x1;
static const uint8_t LA_bit = 0x2;
Expand All @@ -768,7 +771,7 @@ public:
}

IPv6Prefix(const IPv6Prefix& rhs)
: _version(rhs._version), _use_metric(rhs._use_metric)
: Invalid(rhs), _version(rhs._version), _use_metric(rhs._use_metric)
{
copy(rhs);
}
Expand All @@ -786,6 +789,7 @@ public:
ipv6prefix_copy(_network);
ipv6prefix_copy(_metric);
ipv6prefix_copy(_prefix_options);
set_invalid(rhs.invalid());
}
#undef ipv6prefix_copy

Expand All @@ -806,8 +810,7 @@ public:
* @return A IPv6Prefix.
*/
IPv6Prefix decode(uint8_t *ptr, size_t& len, uint8_t prefixlen,
uint8_t option) const
throw(InvalidPacket);
uint8_t option, string& err) const;

/**
* Copy a wire format representation to the pointer provided.
Expand Down Expand Up @@ -897,6 +900,10 @@ public:
*/
string str() const;

virtual bool invalid() const {
return (Invalid::invalid() || _network.invalid());
}

private:
const OspfTypes::Version _version;
const bool _use_metric;
Expand All @@ -909,7 +916,7 @@ private:
/**
* Defines a link/interface, carried in a RouterLsa.
*/
class RouterLink {
class RouterLink : public Invalid {
public:
enum Type {
p2p = 1, // Point-to-point connection to another router
Expand All @@ -924,7 +931,7 @@ class RouterLink {
_neighbour_router_id(0)
{}

RouterLink(const RouterLink& rhs) : _version(rhs._version) {
RouterLink(const RouterLink& rhs) : Invalid(rhs), _version(rhs._version) {
copy(rhs);
}

Expand All @@ -951,6 +958,7 @@ class RouterLink {
routerlink_copy(_neighbour_router_id);
break;
}
set_invalid(rhs.invalid());
}
#undef routerlink_copy

Expand Down Expand Up @@ -989,8 +997,7 @@ class RouterLink {
*
* @return A RouterLink.
*/
RouterLink
decode(uint8_t *ptr, size_t& len) const throw(InvalidPacket);
RouterLink decode(uint8_t *ptr, size_t& len, string& err);

/**
* Copy a wire format representation to the pointer provided.
Expand Down Expand Up @@ -1156,7 +1163,7 @@ public:
*
* @return A reference to an LSA that manages its own memory.
*/
LsaRef decode(uint8_t *buf, size_t& len) const throw(InvalidPacket);
LsaRef decode(uint8_t *buf, size_t& len, string& err) const;

bool encode();

Expand Down Expand Up @@ -1223,7 +1230,7 @@ class RouterLsa : public Lsa {
*
* @return A reference to an LSA that manages its own memory.
*/
LsaRef decode(uint8_t *buf, size_t& len) const throw(InvalidPacket);
LsaRef decode(uint8_t *buf, size_t& len, string& err) const;

bool encode();

Expand Down Expand Up @@ -1363,7 +1370,7 @@ class NetworkLsa : public Lsa {
*
* @return A reference to an LSA that manages its own memory.
*/
LsaRef decode(uint8_t *buf, size_t& len) const throw(InvalidPacket);
LsaRef decode(uint8_t *buf, size_t& len, string& err) const;

bool encode();

Expand Down Expand Up @@ -1467,7 +1474,7 @@ class SummaryNetworkLsa : public Lsa {
*
* @return A reference to an LSA that manages its own memory.
*/
LsaRef decode(uint8_t *buf, size_t& len) const throw(InvalidPacket);
LsaRef decode(uint8_t *buf, size_t& len, string& err) const;

bool encode();

Expand Down Expand Up @@ -1510,7 +1517,11 @@ class SummaryNetworkLsa : public Lsa {
* Generate a printable representation.
*/
string str() const;


virtual bool invalid() const {
return (Invalid::invalid() || _ipv6prefix.invalid());
}

private:
uint32_t _metric;
uint32_t _network_mask; // OSPFv2 only.
Expand Down Expand Up @@ -1570,7 +1581,7 @@ class SummaryRouterLsa : public Lsa {
*
* @return A reference to an LSA that manages its own memory.
*/
LsaRef decode(uint8_t *buf, size_t& len) const throw(InvalidPacket);
LsaRef decode(uint8_t *buf, size_t& len, string& err) const;

bool encode();

Expand Down Expand Up @@ -1696,7 +1707,7 @@ class ASExternalLsa : public Lsa {
*
* @return A reference to an LSA that manages its own memory.
*/
LsaRef decode(uint8_t *buf, size_t& len) const throw(InvalidPacket);
LsaRef decode(uint8_t *buf, size_t& len, string& err) const;

bool encode();

Expand Down Expand Up @@ -1875,7 +1886,12 @@ class ASExternalLsa : public Lsa {
* Generate a printable representation.
*/
string str() const;


virtual bool invalid() const {
return (Invalid::invalid() || _ipv6prefix.invalid() || _forwarding_address.invalid()
|| _forwarding_address_ipv4.invalid() || _forwarding_address_ipv6.invalid());
}

private:
uint32_t _network_mask; // OSPFv2 only.
bool _e_bit;
Expand Down Expand Up @@ -1991,7 +2007,7 @@ public:
*
* @return A reference to an LSA that manages its own memory.
*/
LsaRef decode(uint8_t *buf, size_t& len) const throw(InvalidPacket);
LsaRef decode(uint8_t *buf, size_t& len, string& err) const;

bool encode();

Expand Down Expand Up @@ -2040,7 +2056,11 @@ public:
* Generate a printable representation.
*/
string str() const;


virtual bool invalid() const {
return (Invalid::invalid() || _link_local_address.invalid());
}

private:
uint8_t _rtr_priority;
uint32_t _options;
Expand Down Expand Up @@ -2086,7 +2106,7 @@ public:
*
* @return A reference to an LSA that manages its own memory.
*/
LsaRef decode(uint8_t *buf, size_t& len) const throw(InvalidPacket);
LsaRef decode(uint8_t *buf, size_t& len, string& err) const;

bool encode();

Expand Down Expand Up @@ -2188,7 +2208,7 @@ class LsaTransmit : class Transmit {
* Link State Request as sent in a Link State Request Packet.
* Never store or pass a pointer, just deal with it inline.
*/
class Ls_request {
class Ls_request : public Invalid {
public:
Ls_request(OspfTypes::Version version) :
_version(version), _ls_type(0),_link_state_id(0),
Expand All @@ -2201,7 +2221,7 @@ class Ls_request {
_advertising_router(advertising_router)
{}

Ls_request(const Ls_request& rhs) {
Ls_request(const Ls_request& rhs) : Invalid(rhs) {
copy(rhs);
}

Expand All @@ -2219,6 +2239,7 @@ class Ls_request {
ls_copy(_ls_type);
ls_copy(_link_state_id);
ls_copy(_advertising_router);
set_invalid(rhs.invalid());
}
#undef ls_copy

Expand All @@ -2230,8 +2251,7 @@ class Ls_request {
/**
* Decode a Link State Request and return value inline not a pointer.
*/
Ls_request
decode(uint8_t *ptr) throw(InvalidPacket);
Ls_request decode(uint8_t *ptr, string& err);

/**
* Copy a wire format representation to the pointer provided.
Expand Down

0 comments on commit 1dd2c2b

Please sign in to comment.