ns3-bgp  0.2
BGP module for ns-3.
bgp.h
1 
11 #ifndef BGP_H
12 #define BGP_H
13 
14 #include <vector>
15 #include "bgp-ns3-fsm.h"
16 #include "bgp-ns3-clock.h"
17 #include "bgp-ns3-socket-out.h"
18 #include "bgp-log.h"
19 #include "bgp-routing.h"
20 #include "bgp-ns3-socket-in.h"
21 #include "ns3/application.h"
22 #include "ns3/ipv4-address.h"
23 #include "ns3/socket.h"
24 
25 namespace ns3 {
26 
27 class Bgp;
28 class BgpNs3SocketIn;
29 
34 class Peer : public SimpleRefCount<Peer> {
35 public:
36  Peer();
37 
38  uint32_t local_asn;
39  uint32_t peer_asn;
40  Ipv4Address peer_address;
43 
44  bool passive;
45  int8_t allow_local_as;
46  int32_t weight;
50 
51  uint8_t ebgp_multihop;
52 
53 };
54 
59 class Session : public SimpleRefCount<Session> {
60 public:
61  Ptr<Peer> peer;
62  Ptr<BgpNs3Fsm> fsm;
63  Ptr<Socket> socket;
64  Ptr<BgpLog> logger;
65  Ptr<BgpNs3SocketOut> out_handler;
66  Ptr<BgpNs3SocketIn> in_handler;
67 
68  bool local_init;
69 
70  void Drop();
71 };
72 
77 class Bgp : public Application {
78 public:
79  Bgp();
80  static TypeId GetTypeId (void);
81 
82  void StartApplication(void);
83  void StopApplication(void);
84 
85  void AddPeer(const Peer &peer);
86  void AddRoute(libbgp::Prefix4 route, uint32_t nexthop);
87  void AddRoute(uint32_t prefix, uint8_t mask, uint32_t nexthop);
88  void AddRoute(const Ipv4Address &prefix, const Ipv4Mask &mask, const Ipv4Address &nexthop);
89  void SetLibbgpLogLevel(libbgp::LogLevel log_level);
90  void SetBgpId(Ipv4Address bgp_id);
91  void SetHoldTimer(Time hold_timer);
92  void SetClockInterval(Time interval);
93 
94 private:
95  void Tick();
96 
97  bool ConnectPeer(Ptr<Peer> peer);
98  bool SessionInit(bool local_init, Ptr<Socket> socket);
99 
100  void HandleConnectIn(Ptr<Socket> socket, const Address &src);
101  bool HandleConnectInRequest(Ptr<Socket> socket, const Address &src);
102  void HandleConnectOut(Ptr<Socket> socket);
103  void HandleConnectOutFailed(Ptr<Socket> socket);
104  void HandleClose(Ptr<Socket> socket);
105  void HandleStateChange(Ptr<Socket> socket, int old_state, int new_state);
106 
107  Time _hold_timer;
108  Time _clock_interval;
109  Time _error_hold;
110 
111  BgpLog _logger;
112  BgpNs3Clock _clock;
113  Ipv4Address _bgp_id;
114 
115  Ptr<BgpRouting> _routing;
116  Ptr<Socket> _listen_socket;
117 
118  std::vector<Ptr<Peer>> _peers;
119  std::vector<Ptr<Session>> _sessions;
120 
121  libbgp::BgpConfig _template;
122  libbgp::BgpRib4 _rib;
124  libbgp::LogLevel _log_level;
125 
126  bool _running;
127 };
128 
129 }
130 
131 #endif /* BGP_H */
132 
bool forced_default_nexthop
always use peering IP as nexthop.
Definition: bgp.h:48
Peer configuration class.
Definition: bgp.h:34
ns3 BGP module: routing protocol (Ipv4RoutingProtocol)
Ipv4Address peer_address
peer&#39;s address.
Definition: bgp.h:40
The libbgp log forwarder class.
Definition: bgp-log.h:22
ns3 smart pointer wrapper for libbgp BGP FSM.
libbgp Clock interface for ns3.
bool ibgp_alter_nexthop
alter IBGP nexthop attribute the same way as EBGP.
Definition: bgp.h:49
int32_t weight
weight of this peer
Definition: bgp.h:46
Simple container class for FSM to send data to peer.
libbgp::BgpFilterRules egress_rules
egress router filter rules. See libbgp documents.
Definition: bgp.h:42
int8_t allow_local_as
Allow N local ASN in AS_PATH.
Definition: bgp.h:45
The clock interface. See libbgp document.
Definition: bgp-ns3-clock.h:21
Definition: bgp-log.cc:15
libbgp log forwarder.
bool passive
passive peering (don&#39;t send OPEN)
Definition: bgp.h:44
Simple container class for FSM to receive data from peer.
bool no_nexthop_check
disable nexthop attribute validation
Definition: bgp.h:47
Session information class.
Definition: bgp.h:59
libbgp::BgpFilterRules ingress_rules
ingress router filter rules. See libbgp documents.
Definition: bgp.h:41
uint32_t local_asn
local ASN.
Definition: bgp.h:38
The Bgp Application.
Definition: bgp.h:77
uint32_t peer_asn
peer ASN.
Definition: bgp.h:39