Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Experiment with rewriting Dumper with visitor pattern
Initial part of the rewriting, code is not compiling yet
- Loading branch information
Showing
100 changed files
with
3,216 additions
and
717 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
SUBDIRS=parser dumper examples | ||
SUBDIRS=parser dumper2 | ||
|
||
ACLOCAL_AMFLAGS = -I m4 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
#include <bgpparser.h> | ||
|
||
#include "ASSegmentVisitor.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
#ifndef _ASCII_ATTRS_VISITOR_H_ | ||
#define _ASCII_ATTRS_VISITOR_H_ | ||
|
||
#include <visitors/GJDepthFirst.h> | ||
|
||
class ASSegmentVisitor : public GJDepthFirst | ||
{ | ||
virtual boost::any& visit( AttributeTypeASPathSegment &n, boost::any ¶m ) | ||
{ | ||
string head = ""; | ||
string tail = ""; | ||
string sep = " "; | ||
|
||
switch( n.getPathSegmentType() ) | ||
{ | ||
case AttributeTypeASPathSegment::AS_SEQUENCE: head = ""; tail=""; sep=" "; break; | ||
case AttributeTypeASPathSegment::AS_SET: head = "{"; tail="}", sep=","; break; | ||
case AttributeTypeASPathSegment::AS_CONFED_SEQUENCE: head = "("; tail=")"; sep=" "; break; | ||
case AttributeTypeASPathSegment::AS_CONFED_SET: head = "["; tail="]"; sep=","; break; | ||
} | ||
|
||
ostringstream os; | ||
|
||
os << head; | ||
bool isFirst=true; | ||
BOOST_FOREACH( uint32_t asn, as_seg->getPathSegmentValue() ) | ||
{ | ||
if( isFirst ) | ||
isFirst=false; | ||
else | ||
os << sep; | ||
|
||
os << asn; | ||
} | ||
os << tail; | ||
} | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
#include "AsciiBGPVisitor.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
|
||
#include <bgpparser.h> | ||
#include <visitors/GJVoidDepthFirst.h> | ||
|
||
#include "AttrsVisitor.h" | ||
|
||
#include "Params.h" | ||
|
||
|
||
class AsciiBGPVisitor : public AttrsVisitor | ||
{ | ||
virtual void visit( BGPOpen &n, boost::any ¶m ) | ||
{ | ||
// prevent visiting optional headers | ||
} | ||
|
||
virtual void visit( BGPUpdate &n, boost::any ¶m ) | ||
{ | ||
BOOST_FOREACH( const BGPAttributePtr &attr, n.getPathAttributes() ) | ||
{ | ||
attr->accept( *this, param ); | ||
} | ||
|
||
param.afi=AFI_IPv4; | ||
|
||
BOOST_FOREACH( const RoutePtr &route, n.getWithdrawnRoutes() ) | ||
{ | ||
route->accept( *this, param ); | ||
} | ||
|
||
BOOST_FOREACH( const RoutePtr &route, n.getNlriRoutes() ) | ||
{ | ||
route->accept( *this, param ); | ||
} | ||
} | ||
|
||
virtual void visit( AttributeTypeMPReachNLRI &n, boost::any ¶m ) | ||
{ | ||
param.afi = n.getAFI( ); | ||
param.next_hop = FORMAT_IP_ADDRESS( n.getNextHopAddress(), n.getAFI() ); | ||
|
||
BOOST_FOREACH( const NLRIReachablePtr& route, n.getNLRI() ) | ||
{ | ||
route->accept( *this, param ); | ||
} | ||
|
||
BOOST_FOREACH( const NLRIReachablePtr& route, n.getSNPA() ) | ||
{ | ||
route->accept( *this, param ); | ||
} | ||
} | ||
virtual void visit( AttributeTypeMPUnreachNLRI &n, boost::any ¶m ) | ||
{ | ||
param.afi = n.getAFI( ); | ||
|
||
BOOST_FOREACH( const NLRIUnReachablePtr &route, n.getNLRI() ) | ||
{ | ||
route->accept( *this, param ); | ||
} | ||
} | ||
|
||
virtual void visit( Route &n, boost::any ¶m ) | ||
{ | ||
// n.getLength( ) | ||
// n.getPrefix( ) | ||
// n.getNumOctets( ) | ||
// + helper methods available, see Route | ||
} | ||
|
||
virtual void visit( NLRIReachable &n, boost::any ¶m ) | ||
{ | ||
// n.getLength( ) | ||
// n.getPrefix( ) | ||
// n.getNumOctets( ) | ||
// + helper methods available, see Route | ||
} | ||
virtual void visit( NLRIUnReachable &n, boost::any ¶m ) | ||
{ | ||
std::cout | ||
<< param.mrt_type << "|" << param.timestamp << "|" | ||
<< "W" + "|" + param.peer_addr + "|" + param.peer_as + "|" + n.toString( params.afi ) | ||
<< std::endl; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
#include <bgpparser.h> | ||
|
||
#include <AsciiVisitor.h> |
Oops, something went wrong.