INET Framework for OMNeT++/OMNEST
inet::bgp::BGPRouting Class Reference

#include <BGPRouting.h>

Inheritance diagram for inet::bgp::BGPRouting:
inet::ILifecycle inet::TCPSocket::CallbackInterface

Public Member Functions

 BGPRouting ()
 
virtual ~BGPRouting ()
 
- Public Member Functions inherited from inet::ILifecycle
virtual ~ILifecycle ()
 
- Public Member Functions inherited from inet::TCPSocket::CallbackInterface
virtual ~CallbackInterface ()
 
virtual void socketStatusArrived (int connId, void *yourPtr, TCPStatusInfo *status)
 
virtual void socketDeleted (int connId, void *yourPtr)
 

Protected Member Functions

virtual int numInitStages () const override
 
virtual void initialize (int stage) override
 
virtual void handleMessage (cMessage *msg) override
 
virtual bool handleOperationStage (LifecycleOperation *operation, int stage, IDoneCallback *doneCallback) override
 Perform one stage of a lifecycle operation. More...
 
virtual void finish () override
 
virtual void socketDataArrived (int connId, void *yourPtr, cPacket *msg, bool urgent) override
 
virtual void socketEstablished (int connId, void *yourPtr) override
 
virtual void socketFailure (int connId, void *yourPtr, int code) override
 
virtual void socketPeerClosed (int connId, void *yourPtr) override
 
virtual void socketClosed (int connId, void *yourPtr) override
 
void getScheduleAt (simtime_t t, cMessage *msg)
 
simtime_t getSimTime ()
 
void getCancelAndDelete (cMessage *msg)
 
cMessage * getCancelEvent (cMessage *msg)
 
cGate * getGate (const char *gateName)
 
IIPv4RoutingTablegetIPRoutingTable ()
 
std::vector< RoutingTableEntry * > getBGPRoutingTable ()
 
void listenConnectionFromPeer (SessionID sessionID)
 active listenSocket for a given session (used by fsm) More...
 
void openTCPConnectionToPeer (SessionID sessionID)
 active TCPConnection for a given session (used by fsm) More...
 
void updateSendProcess (const unsigned char decisionProcessResult, SessionID sessionIndex, RoutingTableEntry *entry)
 RFC 4271, 9.2 : Update-Send Process / Sent or not new UPDATE messages to its peers. More...
 
SessionID findNextSession (BGPSessionType type, bool startSession=false)
 find the next SessionID compared to his type and start this session if boolean is true More...
 
bool checkExternalRoute (const IPv4Route *ospfRoute)
 check if the route is in OSPF external IPv4RoutingTable More...
 

Private Types

typedef std::vector< RoutingTableEntry * > RoutingTableEntryVector
 

Private Member Functions

void handleTimer (cMessage *timer)
 
void processMessageFromTCP (cMessage *msg)
 
void processMessage (const BGPOpenMessage &msg)
 
void processMessage (const BGPKeepAliveMessage &msg)
 
void processMessage (const BGPUpdateMessage &msg)
 
bool deleteBGPRoutingEntry (RoutingTableEntry *entry)
 
unsigned char decisionProcess (const BGPUpdateMessage &msg, RoutingTableEntry *entry, SessionID sessionIndex)
 RFC 4271: 9.1. More...
 
bool tieBreakingProcess (RoutingTableEntry *oldEntry, RoutingTableEntry *entry)
 RFC 4271: 9.1.2.2 Breaking Ties used when BGP speaker may have several routes to the same destination that have the same degree of preference. More...
 
SessionID createSession (BGPSessionType typeSession, const char *peerAddr)
 
bool isInASList (std::vector< ASID > ASList, RoutingTableEntry *entry)
 
unsigned long isInTable (std::vector< RoutingTableEntry * > rtTable, RoutingTableEntry *entry)
 
std::vector< const char * > loadASConfig (cXMLElementList &ASConfig)
 
void loadSessionConfig (cXMLElementList &sessionList, simtime_t *delayTab)
 
void loadConfigFromXML (cXMLElement *bgpConfig)
 
ASID findMyAS (cXMLElementList &ASList, int &outRouterPosition)
 
bool ospfExist (IIPv4RoutingTable *rtTable)
 
void loadTimerConfig (cXMLElementList &timerConfig, simtime_t *delayTab)
 
unsigned char asLoopDetection (RoutingTableEntry *entry, ASID myAS)
 
SessionID findIdFromPeerAddr (std::map< SessionID, BGPSession * > sessions, IPv4Address peerAddr)
 
int isInRoutingTable (IIPv4RoutingTable *rtTable, IPv4Address addr)
 
int isInInterfaceTable (IInterfaceTable *rtTable, IPv4Address addr)
 
SessionID findIdFromSocketConnId (std::map< SessionID, BGPSession * > sessions, int connId)
 
unsigned int calculateStartDelay (int rtListSize, unsigned char rtPosition, unsigned char rtPeerPosition)
 

Private Attributes

TCPSocketMap _socketMap
 
ASID _myAS = 0
 
SessionID _currSessionId = 0
 
IInterfaceTable_inft = nullptr
 
IIPv4RoutingTable_rt = nullptr
 
RoutingTableEntryVector _BGPRoutingTable
 
RoutingTableEntryVector _prefixListIN
 
RoutingTableEntryVector _prefixListOUT
 
RoutingTableEntryVector _prefixListINOUT
 
std::vector< ASID_ASListIN
 
std::vector< ASID_ASListOUT
 
std::map< SessionID, BGPSession * > _BGPSessions
 

Static Private Attributes

static const int BGP_TCP_CONNECT_VALID = 71
 
static const int BGP_TCP_CONNECT_CONFIRM = 72
 
static const int BGP_TCP_CONNECT_FAILED = 73
 
static const int BGP_TCP_CONNECT_OPEN_RCV = 74
 
static const int BGP_TCP_KEEP_ALIVE_RCV = 75
 

Friends

class BGPSession
 

Member Typedef Documentation

Constructor & Destructor Documentation

inet::bgp::BGPRouting::BGPRouting ( )
inline
43 {}
inet::bgp::BGPRouting::~BGPRouting ( void  )
virtual
31 {
32  for (auto & elem : _BGPSessions)
33  {
34  delete (elem).second;
35  }
36 
37  for (auto & elem : _prefixListINOUT) {
38  delete (elem);
39  }
40 }
std::map< SessionID, BGPSession * > _BGPSessions
Definition: BGPRouting.h:145
RoutingTableEntryVector _prefixListINOUT
Definition: BGPRouting.h:142

Member Function Documentation

unsigned char inet::bgp::BGPRouting::asLoopDetection ( RoutingTableEntry entry,
ASID  myAS 
)
private

Referenced by processMessage().

789 {
790  for (unsigned int i = 1; i < entry->getASCount(); i++) {
791  if (myAS == entry->getAS(i)) {
792  return ASLOOP_DETECTED;
793  }
794  }
795  return ASLOOP_NO_DETECTED;
796 }
const unsigned char ASLOOP_NO_DETECTED
Definition: BGPCommon.h:48
const unsigned char ASLOOP_DETECTED
Definition: BGPCommon.h:49
unsigned int inet::bgp::BGPRouting::calculateStartDelay ( int  rtListSize,
unsigned char  rtPosition,
unsigned char  rtPeerPosition 
)
private

Referenced by loadConfigFromXML().

633 {
634  unsigned int startDelay = 0;
635  if (rtPeerPosition == 1) {
636  if (rtPosition == 1) {
637  startDelay = 1;
638  }
639  else {
640  startDelay = (rtPosition - 1) * 2;
641  }
642  return startDelay;
643  }
644 
645  if (rtPosition < rtPeerPosition) {
646  startDelay = 2;
647  }
648  else if (rtPosition > rtPeerPosition) {
649  startDelay = (rtListSize - 1) * 2 - 2 * (rtPeerPosition - 2);
650  }
651  else {
652  startDelay = (rtListSize - 1) * 2 + 1;
653  }
654  return startDelay;
655 }
bool inet::bgp::BGPRouting::checkExternalRoute ( const IPv4Route ospfRoute)
protected

check if the route is in OSPF external IPv4RoutingTable

Returns
true if it is, false else

Referenced by inet::bgp::BGPSession::checkExternalRoute().

449 {
450  IPv4Address OSPFRoute;
451  OSPFRoute = route->getDestination();
452  ospf::OSPFRouting *ospf = getModuleFromPar<ospf::OSPFRouting>(par("ospfRoutingModule"), this);
453  bool returnValue = ospf->checkExternalRoute(OSPFRoute);
454  return returnValue;
455 }
SessionID inet::bgp::BGPRouting::createSession ( BGPSessionType  typeSession,
const char *  peerAddr 
)
private

Referenced by loadConfigFromXML(), and loadSessionConfig().

658 {
659  BGPSession *newSession = new BGPSession(*this);
660  SessionID newSessionId;
661  SessionInfo info;
662 
663  info.sessionType = typeSession;
664  info.ASValue = _myAS;
665  info.routerID = _rt->getRouterId();
666  info.peerAddr.set(peerAddr);
667  if (typeSession == EGP) {
668  info.linkIntf = _rt->getInterfaceForDestAddr(info.peerAddr);
669  if (info.linkIntf == nullptr) {
670  throw cRuntimeError("BGP Error: No configuration interface for peer address: %s", peerAddr);
671  }
672  info.sessionID = info.peerAddr.getInt() + info.linkIntf->ipv4Data()->getIPAddress().getInt();
673  }
674  else {
675  info.sessionID = info.peerAddr.getInt() + info.routerID.getInt();
676  }
677  newSessionId = info.sessionID;
678  newSession->setInfo(info);
679  _BGPSessions[newSessionId] = newSession;
680 
681  return newSessionId;
682 }
ASID _myAS
Definition: BGPRouting.h:133
virtual InterfaceEntry * getInterfaceForDestAddr(const IPv4Address &dest) const =0
Convenience function based on findBestMatchingRoute().
unsigned long SessionID
Definition: BGPCommon.h:53
std::map< SessionID, BGPSession * > _BGPSessions
Definition: BGPRouting.h:145
Definition: BGPCommon_m.h:48
friend class BGPSession
Definition: BGPRouting.h:60
virtual IPv4Address getRouterId() const =0
Returns routerId.
IIPv4RoutingTable * _rt
Definition: BGPRouting.h:137
void set(uint32 ip)
name Setting the address
Definition: IPv4Address.h:153
unsigned char inet::bgp::BGPRouting::decisionProcess ( const BGPUpdateMessage msg,
RoutingTableEntry entry,
SessionID  sessionIndex 
)
private

RFC 4271: 9.1.

: Decision Process used when an UPDATE message is received As matches, routes are sent or not to UpdateSentProcess The result can be ROUTE_DESTINATION_CHANGED, NEW_ROUTE_ADDED or 0 if no routingTable modification

Referenced by processMessage().

294 {
295  //Don't add the route if it exists in PrefixListINTable or in ASListINTable
296  if (isInTable(_prefixListIN, entry) != (unsigned long)-1 || isInASList(_ASListIN, entry)) {
297  delete entry;
298  return 0;
299  }
300 
301  /*If the AS_PATH attribute of a BGP route contains an AS loop, the BGP
302  route should be excluded from the decision process. */
303  entry->setPathType(msg.getPathAttributeList(0).getOrigin().getValue());
304  entry->setGateway(msg.getPathAttributeList(0).getNextHop().getValue());
305 
306  //if the route already exist in BGP routing table, tieBreakingProcess();
307  //(RFC 4271: 9.1.2.2 Breaking Ties)
308  unsigned long BGPindex = isInTable(_BGPRoutingTable, entry);
309  if (BGPindex != (unsigned long)-1) {
310  if (tieBreakingProcess(_BGPRoutingTable[BGPindex], entry)) {
311  delete entry;
312  return 0;
313  }
314  else {
315  entry->setInterface(_BGPSessions[sessionIndex]->getLinkIntf());
316  _BGPRoutingTable.push_back(entry);
317  _rt->addRoute(entry);
319  }
320  }
321 
322  //Don't add the route if it exists in IPv4 routing table except if the msg come from IGP session
323  int indexIP = isInRoutingTable(_rt, entry->getDestination());
324  if (indexIP != -1 && _rt->getRoute(indexIP)->getSourceType() != IRoute::BGP) {
325  if (_BGPSessions[sessionIndex]->getType() != IGP) {
326  delete entry;
327  return 0;
328  }
329  else {
330  IPv4Route *oldEntry = _rt->getRoute(indexIP);
331  IPv4Route *newEntry = new IPv4Route;
332  newEntry->setDestination(oldEntry->getDestination());
333  newEntry->setNetmask(oldEntry->getNetmask());
334  newEntry->setGateway(oldEntry->getGateway());
335  newEntry->setInterface(oldEntry->getInterface());
336  newEntry->setSourceType(IRoute::BGP);
337  _rt->deleteRoute(oldEntry);
338  _rt->addRoute(newEntry);
339  //FIXME model error: the RoutingTableEntry *entry will be stored in _BGPRoutingTable, but not stored in _rt, memory leak
340  //FIXME model error: The entry inserted to _BGPRoutingTable, but newEntry inserted to _rt; entry and newEntry are differ.
341  }
342  }
343 
344  entry->setInterface(_BGPSessions[sessionIndex]->getLinkIntf());
345  _BGPRoutingTable.push_back(entry);
346 
347  if (_BGPSessions[sessionIndex]->getType() == EGP) {
348  std::string entryh = entry->getDestination().str();
349  std::string entryn = entry->getNetmask().str();
350  _rt->addRoute(entry);
351  //insertExternalRoute on OSPF ExternalRoutingTable if OSPF exist on this BGP router
352  if (ospfExist(_rt)) {
353  ospf::IPv4AddressRange OSPFnetAddr;
354  OSPFnetAddr.address = entry->getDestination();
355  OSPFnetAddr.mask = entry->getNetmask();
356  ospf::OSPFRouting *ospf = getModuleFromPar<ospf::OSPFRouting>(par("ospfRoutingModule"), this);
357  InterfaceEntry *ie = entry->getInterface();
358  if (!ie)
359  throw cRuntimeError("Model error: interface entry is nullptr");
360  ospf->insertExternalRoute(ie->getInterfaceId(), OSPFnetAddr);
361  }
362  }
363  return NEW_ROUTE_ADDED; //FIXME model error: When returns NEW_ROUTE_ADDED then entry stored in _BGPRoutingTable, but sometimes not stored in _rt
364 }
RoutingTableEntryVector _BGPRoutingTable
Definition: BGPRouting.h:139
bool ospfExist(IIPv4RoutingTable *rtTable)
Definition: BGPRouting.cc:778
std::vector< ASID > _ASListIN
Definition: BGPRouting.h:143
unsigned long isInTable(std::vector< RoutingTableEntry * > rtTable, RoutingTableEntry *entry)
Definition: BGPRouting.cc:751
virtual IPv4Route * getRoute(int k) const override=0
Returns the kth route.
std::map< SessionID, BGPSession * > _BGPSessions
Definition: BGPRouting.h:145
managed by the given routing protocol
Definition: IRoute.h:47
virtual bool deleteRoute(IPv4Route *entry)=0
Deletes the given route from the routing table.
bool tieBreakingProcess(RoutingTableEntry *oldEntry, RoutingTableEntry *entry)
RFC 4271: 9.1.2.2 Breaking Ties used when BGP speaker may have several routes to the same destination...
Definition: BGPRouting.cc:366
bool isInASList(std::vector< ASID > ASList, RoutingTableEntry *entry)
Definition: BGPRouting.cc:765
SourceType getSourceType() const override
Source of route.
Definition: IPv4Route.h:120
Definition: BGPCommon_m.h:48
const unsigned char ROUTE_DESTINATION_CHANGED
Definition: BGPCommon.h:45
int isInRoutingTable(IIPv4RoutingTable *rtTable, IPv4Address addr)
Definition: BGPRouting.cc:717
virtual void addRoute(IPv4Route *entry)=0
Adds a route to the routing table.
virtual void setDestination(IPv4Address _dest)
Definition: IPv4Route.h:96
const unsigned char NEW_ROUTE_ADDED
Definition: BGPCommon.h:46
IIPv4RoutingTable * _rt
Definition: BGPRouting.h:137
Definition: BGPCommon_m.h:47
RoutingTableEntryVector _prefixListIN
Definition: BGPRouting.h:140
bool inet::bgp::BGPRouting::deleteBGPRoutingEntry ( RoutingTableEntry entry)
private

Referenced by tieBreakingProcess().

701 {
702  for (auto it = _BGPRoutingTable.begin();
703  it != _BGPRoutingTable.end(); it++)
704  {
705  if (((*it)->getDestination().getInt() & (*it)->getNetmask().getInt()) ==
706  (entry->getDestination().getInt() & entry->getNetmask().getInt()))
707  {
708  _BGPRoutingTable.erase(it);
709  _rt->deleteRoute(entry);
710  return true;
711  }
712  }
713  return false;
714 }
RoutingTableEntryVector _BGPRoutingTable
Definition: BGPRouting.h:139
virtual bool deleteRoute(IPv4Route *entry)=0
Deletes the given route from the routing table.
IIPv4RoutingTable * _rt
Definition: BGPRouting.h:137
SessionID inet::bgp::BGPRouting::findIdFromPeerAddr ( std::map< SessionID, BGPSession * >  sessions,
IPv4Address  peerAddr 
)
private

Referenced by processMessageFromTCP().

685 {
686  for (auto & session : sessions)
687  {
688  if ((session).second->getPeerAddr().equals(peerAddr)) {
689  return (session).first;
690  }
691  }
692  return -1;
693 }
SessionID inet::bgp::BGPRouting::findIdFromSocketConnId ( std::map< SessionID, BGPSession * >  sessions,
int  connId 
)
private

Referenced by socketDataArrived(), socketEstablished(), and socketFailure().

739 {
740  for (auto & session : sessions)
741  {
742  TCPSocket *socket = (session).second->getSocket();
743  if (socket->getConnectionId() == connId) {
744  return (session).first;
745  }
746  }
747  return -1;
748 }
az accept haszálja pcb új connId
Definition: lwip_tcp.txt:38
ASID inet::bgp::BGPRouting::findMyAS ( cXMLElementList &  ASList,
int &  outRouterPosition 
)
private

Referenced by loadConfigFromXML().

477 {
478  // find my own IPv4 address in the configuration file and return the AS id under which it is configured
479  // and also the 1 based position of the entry inside the AS config element
480  for (auto & elem : asList) {
481  cXMLElementList routerList = (elem)->getChildrenByTagName("Router");
482  outRouterPosition = 1;
483  for (auto & routerList_routerListIt : routerList) {
484  IPv4Address routerAddr = IPv4Address((routerList_routerListIt)->getAttribute("interAddr"));
485  for (int i = 0; i < _inft->getNumInterfaces(); i++) {
486  if (_inft->getInterface(i)->ipv4Data()->getIPAddress() == routerAddr)
487  return atoi((routerList_routerListIt)->getParentNode()->getAttribute("id"));
488  }
489  outRouterPosition++;
490  }
491  }
492 
493  return 0;
494 }
IPv4InterfaceData * ipv4Data() const
Definition: InterfaceEntry.h:221
virtual int getNumInterfaces() const =0
Returns the number of interfaces.
IPv4Address getIPAddress() const
Definition: IPv4InterfaceData.h:177
IInterfaceTable * _inft
Definition: BGPRouting.h:136
virtual InterfaceEntry * getInterface(int pos) const =0
Returns the InterfaceEntry specified by an index 0..numInterfaces-1.
SessionID inet::bgp::BGPRouting::findNextSession ( BGPSessionType  type,
bool  startSession = false 
)
protected

find the next SessionID compared to his type and start this session if boolean is true

Referenced by inet::bgp::BGPSession::findAndStartNextSession(), and socketEstablished().

800 {
801  SessionID sessionID = -1;
802  for (auto & elem : _BGPSessions)
803  {
804  if ((elem).second->getType() == type && !(elem).second->isEstablished()) {
805  sessionID = (elem).first;
806  break;
807  }
808  }
809  if (startSession == true && type == IGP && sessionID != (SessionID)-1) {
810  InterfaceEntry *linkIntf = _rt->getInterfaceForDestAddr(_BGPSessions[sessionID]->getPeerAddr());
811  if (linkIntf == nullptr) {
812  throw cRuntimeError("No configuration interface for peer address: %s", _BGPSessions[sessionID]->getPeerAddr().str().c_str());
813  }
814  _BGPSessions[sessionID]->setlinkIntf(linkIntf);
815  _BGPSessions[sessionID]->startConnection();
816  }
817  return sessionID;
818 }
virtual InterfaceEntry * getInterfaceForDestAddr(const IPv4Address &dest) const =0
Convenience function based on findBestMatchingRoute().
unsigned long SessionID
Definition: BGPCommon.h:53
std::map< SessionID, BGPSession * > _BGPSessions
Definition: BGPRouting.h:145
IIPv4RoutingTable * _rt
Definition: BGPRouting.h:137
Definition: BGPCommon_m.h:47
void inet::bgp::BGPRouting::finish ( )
overrideprotectedvirtual
115 {
116  unsigned int statTab[NB_STATS] = {
117  0, 0, 0, 0, 0, 0
118  };
119  for (auto & elem : _BGPSessions) {
120  (elem).second->getStatistics(statTab);
121  }
122  recordScalar("OPENMsgSent", statTab[0]);
123  recordScalar("OPENMsgRecv", statTab[1]);
124  recordScalar("KeepAliveMsgSent", statTab[2]);
125  recordScalar("KeepAliveMsgRcv", statTab[3]);
126  recordScalar("UpdateMsgSent", statTab[4]);
127  recordScalar("UpdateMsgRcv", statTab[5]);
128 }
std::map< SessionID, BGPSession * > _BGPSessions
Definition: BGPRouting.h:145
const unsigned char NB_STATS
Definition: BGPCommon.h:41
std::vector<RoutingTableEntry *> inet::bgp::BGPRouting::getBGPRoutingTable ( )
inlineprotected

Referenced by inet::bgp::BGPSession::getBGPRoutingTable().

68 { return _BGPRoutingTable; }
RoutingTableEntryVector _BGPRoutingTable
Definition: BGPRouting.h:139
void inet::bgp::BGPRouting::getCancelAndDelete ( cMessage *  msg)
inlineprotected

Referenced by inet::bgp::BGPSession::~BGPSession().

64 { return cancelAndDelete(msg); }
cMessage* inet::bgp::BGPRouting::getCancelEvent ( cMessage *  msg)
inlineprotected
cGate* inet::bgp::BGPRouting::getGate ( const char *  gateName)
inlineprotected
66 { return gate(gateName); }
IIPv4RoutingTable* inet::bgp::BGPRouting::getIPRoutingTable ( )
inlineprotected

Referenced by inet::bgp::BGPSession::getIPRoutingTable().

67 { return _rt; }
IIPv4RoutingTable * _rt
Definition: BGPRouting.h:137
void inet::bgp::BGPRouting::getScheduleAt ( simtime_t  t,
cMessage *  msg 
)
inlineprotected
void inet::bgp::BGPRouting::handleMessage ( cMessage *  msg)
overrideprotectedvirtual
66 {
67  if (msg->isSelfMessage()) { //BGP level
68  handleTimer(msg);
69  }
70  else if (!strcmp(msg->getArrivalGate()->getName(), "tcpIn")) { //TCP level
72  }
73  else {
74  delete msg;
75  }
76 }
void handleTimer(cMessage *timer)
Definition: BGPRouting.cc:78
void processMessageFromTCP(cMessage *msg)
Definition: BGPRouting.cc:164
bool inet::bgp::BGPRouting::handleOperationStage ( LifecycleOperation operation,
int  stage,
IDoneCallback doneCallback 
)
overrideprotectedvirtual

Perform one stage of a lifecycle operation.

Processing may be done entirely within this method, or may be a longer process that involves nonzero simulation time or several events, and is triggered by this method call.

Return value: true = "done"; false = "not yet done, will invoke doneCallback when done"

Implements inet::ILifecycle.

110 {
111  throw cRuntimeError("Lifecycle operation support not implemented");
112 }
void inet::bgp::BGPRouting::handleTimer ( cMessage *  timer)
private

Referenced by handleMessage().

79 {
80  BGPSession *pSession = (BGPSession *)timer->getContextPointer();
81  if (pSession) {
82  switch (timer->getKind()) {
83  case START_EVENT_KIND:
84  EV_INFO << "Processing Start Event" << std::endl;
85  pSession->getFSM()->ManualStart();
86  break;
87 
88  case CONNECT_RETRY_KIND:
89  EV_INFO << "Expiring Connect Retry Timer" << std::endl;
90  pSession->getFSM()->ConnectRetryTimer_Expires();
91  break;
92 
93  case HOLD_TIME_KIND:
94  EV_INFO << "Expiring Hold Timer" << std::endl;
95  pSession->getFSM()->HoldTimer_Expires();
96  break;
97 
98  case KEEP_ALIVE_KIND:
99  EV_INFO << "Expiring Keep Alive timer" << std::endl;
100  pSession->getFSM()->KeepaliveTimer_Expires();
101  break;
102 
103  default:
104  throw cRuntimeError("Invalid timer kind %d", timer->getKind());
105  }
106  }
107 }
const unsigned char CONNECT_RETRY_KIND
Definition: BGPCommon.h:37
friend class BGPSession
Definition: BGPRouting.h:60
const unsigned char HOLD_TIME_KIND
Definition: BGPCommon.h:38
const unsigned char KEEP_ALIVE_KIND
Definition: BGPCommon.h:39
const unsigned char START_EVENT_KIND
Definition: BGPCommon.h:36
void inet::bgp::BGPRouting::initialize ( int  stage)
overrideprotectedvirtual
43 {
44  cSimpleModule::initialize(stage);
45 
46  if (stage == INITSTAGE_ROUTING_PROTOCOLS) {
47  bool isOperational;
48  NodeStatus *nodeStatus = dynamic_cast<NodeStatus *>(findContainingNode(this)->getSubmodule("status"));
49  isOperational = (!nodeStatus) || nodeStatus->getState() == NodeStatus::UP;
50  if (!isOperational)
51  throw cRuntimeError("This module doesn't support starting in node DOWN state");
52 
53  // we must wait until IPv4RoutingTable is completely initialized
54  _rt = getModuleFromPar<IIPv4RoutingTable>(par("routingTableModule"), this);
55  _inft = getModuleFromPar<IInterfaceTable>(par("interfaceTableModule"), this);
56 
57  // read BGP configuration
58  cXMLElement *bgpConfig = par("bgpConfig").xmlValue();
59  loadConfigFromXML(bgpConfig);
60  createWatch("myAutonomousSystem", _myAS);
61  WATCH_PTRVECTOR(_BGPRoutingTable);
62  }
63 }
RoutingTableEntryVector _BGPRoutingTable
Definition: BGPRouting.h:139
ASID _myAS
Definition: BGPRouting.h:133
void loadConfigFromXML(cXMLElement *bgpConfig)
Definition: BGPRouting.cc:578
Initialization of routing protocols.
Definition: InitStages.h:101
cModule * findContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:56
IInterfaceTable * _inft
Definition: BGPRouting.h:136
IIPv4RoutingTable * _rt
Definition: BGPRouting.h:137
Definition: NodeStatus.h:40
bool inet::bgp::BGPRouting::isInASList ( std::vector< ASID ASList,
RoutingTableEntry entry 
)
private

Referenced by decisionProcess(), and updateSendProcess().

766 {
767  for (auto & elem : ASList) {
768  for (unsigned int i = 0; i < entry->getASCount(); i++) {
769  if ((elem) == entry->getAS(i)) {
770  return true;
771  }
772  }
773  }
774  return false;
775 }
int inet::bgp::BGPRouting::isInInterfaceTable ( IInterfaceTable rtTable,
IPv4Address  addr 
)
private

Referenced by loadASConfig(), and loadSessionConfig().

729 {
730  for (int i = 0; i < ifTable->getNumInterfaces(); i++) {
731  if (ifTable->getInterface(i)->ipv4Data()->getIPAddress() == addr) {
732  return i;
733  }
734  }
735  return -1;
736 }
int inet::bgp::BGPRouting::isInRoutingTable ( IIPv4RoutingTable rtTable,
IPv4Address  addr 
)
private

Referenced by decisionProcess().

718 {
719  for (int i = 0; i < rtTable->getNumRoutes(); i++) {
720  const IPv4Route *entry = rtTable->getRoute(i);
721  if (IPv4Address::maskedAddrAreEqual(addr, entry->getDestination(), entry->getNetmask())) {
722  return i;
723  }
724  }
725  return -1;
726 }
static bool maskedAddrAreEqual(const IPv4Address &addr1, const IPv4Address &addr2, const IPv4Address &netmask)
Test if the masked addresses (ie the mask is applied to addr1 and addr2) are equal.
Definition: IPv4Address.cc:260
unsigned long inet::bgp::BGPRouting::isInTable ( std::vector< RoutingTableEntry * >  rtTable,
RoutingTableEntry entry 
)
private

Referenced by decisionProcess(), and updateSendProcess().

752 {
753  for (unsigned long i = 0; i < rtTable.size(); i++) {
754  RoutingTableEntry *entryCur = rtTable[i];
755  if ((entry->getDestination().getInt() & entry->getNetmask().getInt()) ==
756  (entryCur->getDestination().getInt() & entryCur->getNetmask().getInt()))
757  {
758  return i;
759  }
760  }
761  return -1;
762 }
void inet::bgp::BGPRouting::listenConnectionFromPeer ( SessionID  sessionID)
protected

active listenSocket for a given session (used by fsm)

Referenced by inet::bgp::BGPSession::listenConnectionFromPeer().

131 {
132  if (_BGPSessions[sessionID]->getSocketListen()->getState() == TCPSocket::CLOSED) {
133  //session StartDelayTime error, it's anormal that listenSocket is closed.
134  _socketMap.removeSocket(_BGPSessions[sessionID]->getSocketListen());
135  _BGPSessions[sessionID]->getSocketListen()->abort();
136  _BGPSessions[sessionID]->getSocketListen()->renewSocket();
137  }
138  if (_BGPSessions[sessionID]->getSocketListen()->getState() != TCPSocket::LISTENING) {
139  _BGPSessions[sessionID]->getSocketListen()->setOutputGate(gate("tcpOut"));
140  _BGPSessions[sessionID]->getSocketListen()->readDataTransferModePar(*this);
141  _BGPSessions[sessionID]->getSocketListen()->bind(TCP_PORT);
142  _BGPSessions[sessionID]->getSocketListen()->listen();
143  }
144 }
Definition: TCPSocket.h:148
std::map< SessionID, BGPSession * > _BGPSessions
Definition: BGPRouting.h:145
const unsigned char TCP_PORT
Definition: BGPCommon.h:34
TCPSocket * removeSocket(TCPSocket *socket)
Removes the given socket from the data structure.
Definition: TCPSocketMap.cc:42
Definition: TCPSocket.h:148
TCPSocketMap _socketMap
Definition: BGPRouting.h:132
std::vector< const char * > inet::bgp::BGPRouting::loadASConfig ( cXMLElementList &  ASConfig)
private

Referenced by loadConfigFromXML().

528 {
529  //create deny Lists
530  std::vector<const char *> routerInSameASList;
531 
532  for (auto & elem : ASConfig) {
533  std::string nodeName = (elem)->getTagName();
534  if (nodeName == "Router") {
535  if (isInInterfaceTable(_inft, IPv4Address((elem)->getAttribute("interAddr"))) == -1) {
536  routerInSameASList.push_back((elem)->getAttribute("interAddr"));
537  }
538  continue;
539  }
540  if (nodeName == "DenyRoute" || nodeName == "DenyRouteIN" || nodeName == "DenyRouteOUT") {
541  RoutingTableEntry *entry = new RoutingTableEntry(); //FIXME Who will delete this entry?
542  entry->setDestination(IPv4Address((elem)->getAttribute("Address")));
543  entry->setNetmask(IPv4Address((elem)->getAttribute("Netmask")));
544  if (nodeName == "DenyRouteIN") {
545  _prefixListIN.push_back(entry);
546  _prefixListINOUT.push_back(entry);
547  }
548  else if (nodeName == "DenyRouteOUT") {
549  _prefixListOUT.push_back(entry);
550  _prefixListINOUT.push_back(entry);
551  }
552  else {
553  _prefixListIN.push_back(entry);
554  _prefixListOUT.push_back(entry);
555  _prefixListINOUT.push_back(entry);
556  }
557  }
558  else if (nodeName == "DenyAS" || nodeName == "DenyASIN" || nodeName == "DenyASOUT") {
559  ASID ASCur = atoi((elem)->getNodeValue());
560  if (nodeName == "DenyASIN") {
561  _ASListIN.push_back(ASCur);
562  }
563  else if (nodeName == "DenyASOUT") {
564  _ASListOUT.push_back(ASCur);
565  }
566  else {
567  _ASListIN.push_back(ASCur);
568  _ASListOUT.push_back(ASCur);
569  }
570  }
571  else {
572  throw cRuntimeError("BGP Error: unknown element named '%s' for AS %u", nodeName.c_str(), _myAS);
573  }
574  }
575  return routerInSameASList;
576 }
std::vector< ASID > _ASListIN
Definition: BGPRouting.h:143
ASID _myAS
Definition: BGPRouting.h:133
RoutingTableEntryVector _prefixListOUT
Definition: BGPRouting.h:141
unsigned short ASID
Definition: BGPCommon.h:52
std::vector< ASID > _ASListOUT
Definition: BGPRouting.h:144
IInterfaceTable * _inft
Definition: BGPRouting.h:136
RoutingTableEntryVector _prefixListINOUT
Definition: BGPRouting.h:142
RoutingTableEntryVector _prefixListIN
Definition: BGPRouting.h:140
int isInInterfaceTable(IInterfaceTable *rtTable, IPv4Address addr)
Definition: BGPRouting.cc:728
void inet::bgp::BGPRouting::loadConfigFromXML ( cXMLElement *  bgpConfig)
private

Referenced by initialize().

579 {
580  if (strcmp(bgpConfig->getTagName(), "BGPConfig"))
581  throw cRuntimeError("Cannot read BGP configuration, unaccepted '%s' node at %s", bgpConfig->getTagName(), bgpConfig->getSourceLocation());
582 
583  // load bgp timer parameters informations
584  simtime_t delayTab[NB_TIMERS];
585  cXMLElement *paramNode = bgpConfig->getElementByPath("TimerParams");
586  if (paramNode == nullptr)
587  throw cRuntimeError("BGP Error: No configuration for BGP timer parameters");
588 
589  cXMLElementList timerConfig = paramNode->getChildren();
590  loadTimerConfig(timerConfig, delayTab);
591 
592  //find my AS
593  cXMLElementList ASList = bgpConfig->getElementsByTagName("AS");
594  int routerPosition;
595  _myAS = findMyAS(ASList, routerPosition);
596  if (_myAS == 0)
597  throw cRuntimeError("BGP Error: No AS configuration for Router ID: %s", _rt->getRouterId().str().c_str());
598 
599  // load EGP Session informations
600  cXMLElementList sessionList = bgpConfig->getElementsByTagName("Session");
601  simtime_t saveStartDelay = delayTab[3];
602  loadSessionConfig(sessionList, delayTab);
603  delayTab[3] = saveStartDelay;
604 
605  // load AS information
606  char ASXPath[32];
607  sprintf(ASXPath, "AS[@id='%d']", _myAS);
608 
609  cXMLElement *ASNode = bgpConfig->getElementByPath(ASXPath);
610  std::vector<const char *> routerInSameASList;
611  if (ASNode == nullptr)
612  throw cRuntimeError("BGP Error: No configuration for AS ID: %d", _myAS);
613 
614  cXMLElementList ASConfig = ASNode->getChildren();
615  routerInSameASList = loadASConfig(ASConfig);
616 
617  //create IGP Session(s)
618  if (routerInSameASList.size()) {
619  unsigned int routerPeerPosition = 1;
620  delayTab[3] += sessionList.size() * 2;
621  for (auto it = routerInSameASList.begin(); it != routerInSameASList.end(); it++, routerPeerPosition++) {
622  SessionID newSessionID;
623  TCPSocket *socketListenIGP = new TCPSocket();
624  newSessionID = createSession(IGP, (*it));
625  delayTab[3] += calculateStartDelay(routerInSameASList.size(), routerPosition, routerPeerPosition);
626  _BGPSessions[newSessionID]->setTimers(delayTab);
627  _BGPSessions[newSessionID]->setSocketListen(socketListenIGP);
628  }
629  }
630 }
std::string str(bool printUnspec=true) const
Returns the string representation of the address (e.g.
Definition: IPv4Address.cc:109
ASID _myAS
Definition: BGPRouting.h:133
unsigned long SessionID
Definition: BGPCommon.h:53
std::map< SessionID, BGPSession * > _BGPSessions
Definition: BGPRouting.h:145
ASID findMyAS(cXMLElementList &ASList, int &outRouterPosition)
Definition: BGPRouting.cc:476
virtual IPv4Address getRouterId() const =0
Returns routerId.
SessionID createSession(BGPSessionType typeSession, const char *peerAddr)
Definition: BGPRouting.cc:657
std::vector< const char * > loadASConfig(cXMLElementList &ASConfig)
Definition: BGPRouting.cc:527
void loadSessionConfig(cXMLElementList &sessionList, simtime_t *delayTab)
Definition: BGPRouting.cc:496
void loadTimerConfig(cXMLElementList &timerConfig, simtime_t *delayTab)
Definition: BGPRouting.cc:457
const unsigned char NB_TIMERS
Definition: BGPCommon.h:40
IIPv4RoutingTable * _rt
Definition: BGPRouting.h:137
Definition: BGPCommon_m.h:47
unsigned int calculateStartDelay(int rtListSize, unsigned char rtPosition, unsigned char rtPeerPosition)
Definition: BGPRouting.cc:632
void inet::bgp::BGPRouting::loadSessionConfig ( cXMLElementList &  sessionList,
simtime_t *  delayTab 
)
private

Referenced by loadConfigFromXML().

497 {
498  simtime_t saveStartDelay = delayTab[3];
499  for (auto sessionListIt = sessionList.begin(); sessionListIt != sessionList.end(); sessionListIt++, delayTab[3] = saveStartDelay) {
500  const char *exterAddr = (*sessionListIt)->getFirstChild()->getAttribute("exterAddr");
501  IPv4Address routerAddr1 = IPv4Address(exterAddr);
502  exterAddr = (*sessionListIt)->getLastChild()->getAttribute("exterAddr");
503  IPv4Address routerAddr2 = IPv4Address(exterAddr);
504  if (isInInterfaceTable(_inft, routerAddr1) == -1 && isInInterfaceTable(_inft, routerAddr2) == -1) {
505  continue;
506  }
507  IPv4Address peerAddr;
508  if (isInInterfaceTable(_inft, routerAddr1) != -1) {
509  peerAddr = routerAddr2;
510  delayTab[3] += atoi((*sessionListIt)->getAttribute("id"));
511  }
512  else {
513  peerAddr = routerAddr1;
514  delayTab[3] += atoi((*sessionListIt)->getAttribute("id")) + 0.5;
515  }
516  if (peerAddr.isUnspecified()) {
517  throw cRuntimeError("BGP Error: No valid external address for session ID : %s", (*sessionListIt)->getAttribute("id"));
518  }
519 
520  SessionID newSessionID = createSession(EGP, peerAddr.str().c_str());
521  _BGPSessions[newSessionID]->setTimers(delayTab);
522  TCPSocket *socketListenEGP = new TCPSocket();
523  _BGPSessions[newSessionID]->setSocketListen(socketListenEGP);
524  }
525 }
unsigned long SessionID
Definition: BGPCommon.h:53
std::map< SessionID, BGPSession * > _BGPSessions
Definition: BGPRouting.h:145
Definition: BGPCommon_m.h:48
SessionID createSession(BGPSessionType typeSession, const char *peerAddr)
Definition: BGPRouting.cc:657
IInterfaceTable * _inft
Definition: BGPRouting.h:136
int isInInterfaceTable(IInterfaceTable *rtTable, IPv4Address addr)
Definition: BGPRouting.cc:728
void inet::bgp::BGPRouting::loadTimerConfig ( cXMLElementList &  timerConfig,
simtime_t *  delayTab 
)
private

Referenced by loadConfigFromXML().

458 {
459  for (auto & elem : timerConfig) {
460  std::string nodeName = (elem)->getTagName();
461  if (nodeName == "connectRetryTime") {
462  delayTab[0] = (double)atoi((elem)->getNodeValue());
463  }
464  else if (nodeName == "holdTime") {
465  delayTab[1] = (double)atoi((elem)->getNodeValue());
466  }
467  else if (nodeName == "keepAliveTime") {
468  delayTab[2] = (double)atoi((elem)->getNodeValue());
469  }
470  else if (nodeName == "startDelay") {
471  delayTab[3] = (double)atoi((elem)->getNodeValue());
472  }
473  }
474 }
virtual int inet::bgp::BGPRouting::numInitStages ( ) const
inlineoverrideprotectedvirtual
48 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
void inet::bgp::BGPRouting::openTCPConnectionToPeer ( SessionID  sessionID)
protected

active TCPConnection for a given session (used by fsm)

Referenced by inet::bgp::BGPSession::openTCPConnectionToPeer().

147 {
148  InterfaceEntry *intfEntry = _BGPSessions[sessionID]->getLinkIntf();
149  TCPSocket *socket = _BGPSessions[sessionID]->getSocket();
150  if (socket->getState() != TCPSocket::NOT_BOUND) {
151  _socketMap.removeSocket(socket);
152  socket->abort();
153  socket->renewSocket();
154  }
155  socket->setCallbackObject(this, (void *)sessionID);
156  socket->setOutputGate(gate("tcpOut"));
157  socket->readDataTransferModePar(*this);
158  socket->bind(intfEntry->ipv4Data()->getIPAddress(), 0);
159  _socketMap.addSocket(socket);
160 
161  socket->connect(_BGPSessions[sessionID]->getPeerAddr(), TCP_PORT);
162 }
void abort()
Aborts the connection.
Definition: TCPSocket.cc:205
std::map< SessionID, BGPSession * > _BGPSessions
Definition: BGPRouting.h:145
const unsigned char TCP_PORT
Definition: BGPCommon.h:34
TCPSocket * removeSocket(TCPSocket *socket)
Removes the given socket from the data structure.
Definition: TCPSocketMap.cc:42
Definition: TCPSocket.h:148
void addSocket(TCPSocket *socket)
Registers the given socket.
Definition: TCPSocketMap.cc:36
TCPSocketMap _socketMap
Definition: BGPRouting.h:132
bool inet::bgp::BGPRouting::ospfExist ( IIPv4RoutingTable rtTable)
private

Referenced by decisionProcess().

779 {
780  for (int i = 0; i < rtTable->getNumRoutes(); i++) {
781  if (rtTable->getRoute(i)->getSourceType() == IRoute::OSPF) {
782  return true;
783  }
784  }
785  return false;
786 }
managed by the given routing protocol
Definition: IRoute.h:46
void inet::bgp::BGPRouting::processMessage ( const BGPOpenMessage msg)
private

Referenced by socketDataArrived().

250 {
251  EV_INFO << "Processing BGP OPEN message" << std::endl;
252  _BGPSessions[_currSessionId]->getFSM()->OpenMsgEvent();
253 }
std::map< SessionID, BGPSession * > _BGPSessions
Definition: BGPRouting.h:145
SessionID _currSessionId
Definition: BGPRouting.h:134
void inet::bgp::BGPRouting::processMessage ( const BGPKeepAliveMessage msg)
private
256 {
257  EV_INFO << "Processing BGP Keep Alive message" << std::endl;
258  _BGPSessions[_currSessionId]->getFSM()->KeepAliveMsgEvent();
259 }
std::map< SessionID, BGPSession * > _BGPSessions
Definition: BGPRouting.h:145
SessionID _currSessionId
Definition: BGPRouting.h:134
void inet::bgp::BGPRouting::processMessage ( const BGPUpdateMessage msg)
private
262 {
263  EV_INFO << "Processing BGP Update message" << std::endl;
264  _BGPSessions[_currSessionId]->getFSM()->UpdateMsgEvent();
265 
266  unsigned char decisionProcessResult;
267  IPv4Address netMask(IPv4Address::ALLONES_ADDRESS);
268  RoutingTableEntry *entry = new RoutingTableEntry();
269  const unsigned char length = msg.getNLRI().length;
270  unsigned int ASValueCount = msg.getPathAttributeList(0).getAsPath(0).getValue(0).getAsValueArraySize();
271 
272  entry->setDestination(msg.getNLRI().prefix);
273  netMask = IPv4Address::makeNetmask(length);
274  entry->setNetmask(netMask);
275  for (unsigned int j = 0; j < ASValueCount; j++) {
276  entry->addAS(msg.getPathAttributeList(0).getAsPath(0).getValue(0).getAsValue(j));
277  }
278 
279  decisionProcessResult = asLoopDetection(entry, _myAS);
280 
281  if (decisionProcessResult == ASLOOP_NO_DETECTED) {
282  // RFC 4271, 9.1. Decision Process
283  decisionProcessResult = decisionProcess(msg, entry, _currSessionId);
284  //RFC 4271, 9.2. Update-Send Process
285  if (decisionProcessResult != 0)
286  updateSendProcess(decisionProcessResult, _currSessionId, entry);
287  }
288  else
289  delete entry;
290 }
ASID _myAS
Definition: BGPRouting.h:133
std::map< SessionID, BGPSession * > _BGPSessions
Definition: BGPRouting.h:145
unsigned char asLoopDetection(RoutingTableEntry *entry, ASID myAS)
Definition: BGPRouting.cc:788
void updateSendProcess(const unsigned char decisionProcessResult, SessionID sessionIndex, RoutingTableEntry *entry)
RFC 4271, 9.2 : Update-Send Process / Sent or not new UPDATE messages to its peers.
Definition: BGPRouting.cc:385
unsigned char decisionProcess(const BGPUpdateMessage &msg, RoutingTableEntry *entry, SessionID sessionIndex)
RFC 4271: 9.1.
Definition: BGPRouting.cc:293
const unsigned char ASLOOP_NO_DETECTED
Definition: BGPCommon.h:48
SessionID _currSessionId
Definition: BGPRouting.h:134
static IPv4Address makeNetmask(int length)
Creates and returns a netmask with the given length.
Definition: IPv4Address.h:335
static const IPv4Address ALLONES_ADDRESS
255.255.255.255
Definition: IPv4Address.h:105
void inet::bgp::BGPRouting::processMessageFromTCP ( cMessage *  msg)
private

Referenced by handleMessage().

165 {
166  TCPSocket *socket = _socketMap.findSocketFor(msg);
167  if (!socket) {
168  socket = new TCPSocket(msg);
169  socket->readDataTransferModePar(*this);
170  socket->setOutputGate(gate("tcpOut"));
171  IPv4Address peerAddr = socket->getRemoteAddress().toIPv4();
173  if (i == (SessionID)-1) {
174  socket->close();
175  delete socket;
176  delete msg;
177  return;
178  }
179  socket->setCallbackObject(this, (void *)i);
180 
181  _socketMap.addSocket(socket);
182  _BGPSessions[i]->getSocket()->abort();
183  _BGPSessions[i]->setSocket(socket);
184  }
185 
186  socket->processMessage(msg);
187 }
unsigned long SessionID
Definition: BGPCommon.h:53
std::map< SessionID, BGPSession * > _BGPSessions
Definition: BGPRouting.h:145
void addSocket(TCPSocket *socket)
Registers the given socket.
Definition: TCPSocketMap.cc:36
SessionID findIdFromPeerAddr(std::map< SessionID, BGPSession * > sessions, IPv4Address peerAddr)
Definition: BGPRouting.cc:684
TCPSocket * findSocketFor(cMessage *msg)
Finds the socket (by connId) for the given message.
Definition: TCPSocketMap.cc:24
TCPSocketMap _socketMap
Definition: BGPRouting.h:132
virtual void inet::bgp::BGPRouting::socketClosed ( int  connId,
void *  yourPtr 
)
inlineoverrideprotectedvirtual

Reimplemented from inet::TCPSocket::CallbackInterface.

58 {}
void inet::bgp::BGPRouting::socketDataArrived ( int  connId,
void *  yourPtr,
cPacket *  msg,
bool  urgent 
)
overrideprotectedvirtual

Implements inet::TCPSocket::CallbackInterface.

216 {
218  if (_currSessionId != (SessionID)-1) {
219  BGPHeader *ptrHdr = check_and_cast<BGPHeader *>(msg);
220  switch (ptrHdr->getType()) {
221  case BGP_OPEN:
222  //BGPOpenMessage* ptrMsg = check_and_cast<BGPOpenMessage*>(msg);
223  processMessage(*check_and_cast<BGPOpenMessage *>(msg));
224  break;
225 
226  case BGP_KEEPALIVE:
227  processMessage(*check_and_cast<BGPKeepAliveMessage *>(msg));
228  break;
229 
230  case BGP_UPDATE:
231  processMessage(*check_and_cast<BGPUpdateMessage *>(msg));
232  break;
233 
234  default:
235  throw cRuntimeError("Invalid BGP message type %d", ptrHdr->getType());
236  }
237  }
238  delete msg;
239 }
az accept haszálja pcb új connId
Definition: lwip_tcp.txt:38
void processMessage(const BGPOpenMessage &msg)
Definition: BGPRouting.cc:249
unsigned long SessionID
Definition: BGPCommon.h:53
std::map< SessionID, BGPSession * > _BGPSessions
Definition: BGPRouting.h:145
Definition: BGPHeader_m.h:58
Definition: BGPHeader_m.h:60
Definition: BGPHeader_m.h:57
SessionID _currSessionId
Definition: BGPRouting.h:134
SessionID findIdFromSocketConnId(std::map< SessionID, BGPSession * > sessions, int connId)
Definition: BGPRouting.cc:738
void inet::bgp::BGPRouting::socketEstablished ( int  connId,
void *  yourPtr 
)
overrideprotectedvirtual

Reimplemented from inet::TCPSocket::CallbackInterface.

190 {
192  if (_currSessionId == (SessionID)-1) {
193  throw cRuntimeError("socket id=%d is not established", connId);
194  }
195 
196  //if it's an IGP Session, TCPConnectionConfirmed only if all EGP Sessions established
197  if (_BGPSessions[_currSessionId]->getType() == IGP &&
198  this->findNextSession(EGP) != (SessionID)-1)
199  {
200  _BGPSessions[_currSessionId]->getFSM()->TcpConnectionFails();
201  }
202  else {
203  _BGPSessions[_currSessionId]->getFSM()->TcpConnectionConfirmed();
204  _BGPSessions[_currSessionId]->getSocketListen()->abort();
205  }
206 
207  if (_BGPSessions[_currSessionId]->getSocketListen()->getConnectionId() != connId &&
208  _BGPSessions[_currSessionId]->getType() == EGP &&
209  this->findNextSession(EGP) != (SessionID)-1)
210  {
211  _BGPSessions[_currSessionId]->getSocketListen()->abort();
212  }
213 }
az accept haszálja pcb új connId
Definition: lwip_tcp.txt:38
unsigned long SessionID
Definition: BGPCommon.h:53
std::map< SessionID, BGPSession * > _BGPSessions
Definition: BGPRouting.h:145
Definition: BGPCommon_m.h:48
SessionID findNextSession(BGPSessionType type, bool startSession=false)
find the next SessionID compared to his type and start this session if boolean is true ...
Definition: BGPRouting.cc:799
SessionID _currSessionId
Definition: BGPRouting.h:134
SessionID findIdFromSocketConnId(std::map< SessionID, BGPSession * > sessions, int connId)
Definition: BGPRouting.cc:738
Definition: BGPCommon_m.h:47
void inet::bgp::BGPRouting::socketFailure ( int  connId,
void *  yourPtr,
int  code 
)
overrideprotectedvirtual

Reimplemented from inet::TCPSocket::CallbackInterface.

242 {
244  if (_currSessionId != (SessionID)-1) {
245  _BGPSessions[_currSessionId]->getFSM()->TcpConnectionFails();
246  }
247 }
az accept haszálja pcb új connId
Definition: lwip_tcp.txt:38
unsigned long SessionID
Definition: BGPCommon.h:53
std::map< SessionID, BGPSession * > _BGPSessions
Definition: BGPRouting.h:145
SessionID _currSessionId
Definition: BGPRouting.h:134
SessionID findIdFromSocketConnId(std::map< SessionID, BGPSession * > sessions, int connId)
Definition: BGPRouting.cc:738
virtual void inet::bgp::BGPRouting::socketPeerClosed ( int  connId,
void *  yourPtr 
)
inlineoverrideprotectedvirtual

Reimplemented from inet::TCPSocket::CallbackInterface.

57 {}
bool inet::bgp::BGPRouting::tieBreakingProcess ( RoutingTableEntry oldEntry,
RoutingTableEntry entry 
)
private

RFC 4271: 9.1.2.2 Breaking Ties used when BGP speaker may have several routes to the same destination that have the same degree of preference.

Returns
bool, true if this process changed the route, false else

Referenced by decisionProcess().

367 {
368  /*a) Remove from consideration all routes that are not tied for
369  having the smallest number of AS numbers present in their
370  AS_PATH attributes.*/
371  if (entry->getASCount() < oldEntry->getASCount()) {
372  deleteBGPRoutingEntry(oldEntry);
373  return false;
374  }
375 
376  /* b) Remove from consideration all routes that are not tied for
377  having the lowest Origin number in their Origin attribute.*/
378  if (entry->getPathType() < oldEntry->getPathType()) {
379  deleteBGPRoutingEntry(oldEntry);
380  return false;
381  }
382  return true;
383 }
bool deleteBGPRoutingEntry(RoutingTableEntry *entry)
Definition: BGPRouting.cc:700
void inet::bgp::BGPRouting::updateSendProcess ( const unsigned char  decisionProcessResult,
SessionID  sessionIndex,
RoutingTableEntry entry 
)
protected

RFC 4271, 9.2 : Update-Send Process / Sent or not new UPDATE messages to its peers.

Referenced by processMessage(), and inet::bgp::BGPSession::updateSendProcess().

386 {
387  //Don't send the update Message if the route exists in listOUTTable
388  //SESSION = EGP : send an update message to all BGP Peer (EGP && IGP)
389  //if it is not the currentSession and if the session is already established
390  //SESSION = IGP : send an update message to External BGP Peer (EGP) only
391  //if it is not the currentSession and if the session is already established
392  for (auto & elem : _BGPSessions)
393  {
394  if (isInTable(_prefixListOUT, entry) != (unsigned long)-1 || isInASList(_ASListOUT, entry) ||
395  ((elem).first == sessionIndex && type != NEW_SESSION_ESTABLISHED) ||
396  (type == NEW_SESSION_ESTABLISHED && (elem).first != sessionIndex) ||
397  !(elem).second->isEstablished())
398  {
399  continue;
400  }
401  if ((_BGPSessions[sessionIndex]->getType() == IGP && (elem).second->getType() == EGP) ||
402  _BGPSessions[sessionIndex]->getType() == EGP ||
403  type == ROUTE_DESTINATION_CHANGED ||
404  type == NEW_SESSION_ESTABLISHED)
405  {
406  BGPUpdateNLRI NLRI;
407  BGPUpdatePathAttributeList content;
408 
409  unsigned int nbAS = entry->getASCount();
410  content.setAsPathArraySize(1);
411  content.getAsPath(0).setValueArraySize(1);
412  content.getAsPath(0).getValue(0).setType(AS_SEQUENCE);
413  //RFC 4271 : set My AS in first position if it is not already
414  if (entry->getAS(0) != _myAS) {
415  content.getAsPath(0).getValue(0).setAsValueArraySize(nbAS + 1);
416  content.getAsPath(0).getValue(0).setLength(1);
417  content.getAsPath(0).getValue(0).setAsValue(0, _myAS);
418  for (unsigned int j = 1; j < nbAS + 1; j++) {
419  content.getAsPath(0).getValue(0).setAsValue(j, entry->getAS(j - 1));
420  }
421  }
422  else {
423  content.getAsPath(0).getValue(0).setAsValueArraySize(nbAS);
424  content.getAsPath(0).getValue(0).setLength(1);
425  for (unsigned int j = 0; j < nbAS; j++) {
426  content.getAsPath(0).getValue(0).setAsValue(j, entry->getAS(j));
427  }
428  }
429 
430  InterfaceEntry *iftEntry = (elem).second->getLinkIntf();
431  content.getOrigin().setValue((elem).second->getType());
432  content.getNextHop().setValue(iftEntry->ipv4Data()->getIPAddress());
433  IPv4Address netMask = entry->getNetmask();
434  NLRI.prefix = entry->getDestination().doAnd(netMask);
435  NLRI.length = (unsigned char)netMask.getNetmaskLength();
436  {
437  BGPUpdateMessage *updateMsg = new BGPUpdateMessage("BGPUpdate");
438  updateMsg->setPathAttributeListArraySize(1);
439  updateMsg->setPathAttributeList(content);
440  updateMsg->setNLRI(NLRI);
441  (elem).second->getSocket()->send(updateMsg);
442  (elem).second->addUpdateMsgSent();
443  }
444  }
445  }
446 }
unsigned long isInTable(std::vector< RoutingTableEntry * > rtTable, RoutingTableEntry *entry)
Definition: BGPRouting.cc:751
ASID _myAS
Definition: BGPRouting.h:133
const unsigned char NEW_SESSION_ESTABLISHED
Definition: BGPCommon.h:47
std::map< SessionID, BGPSession * > _BGPSessions
Definition: BGPRouting.h:145
RoutingTableEntryVector _prefixListOUT
Definition: BGPRouting.h:141
std::vector< ASID > _ASListOUT
Definition: BGPRouting.h:144
bool isInASList(std::vector< ASID > ASList, RoutingTableEntry *entry)
Definition: BGPRouting.cc:765
Definition: BGPCommon_m.h:48
const unsigned char ROUTE_DESTINATION_CHANGED
Definition: BGPCommon.h:45
Definition: BGPCommon_m.h:65
Definition: BGPCommon_m.h:47

Friends And Related Function Documentation

friend class BGPSession
friend

Referenced by createSession().

Member Data Documentation

std::vector<ASID> inet::bgp::BGPRouting::_ASListIN
private

Referenced by decisionProcess(), and loadASConfig().

std::vector<ASID> inet::bgp::BGPRouting::_ASListOUT
private

Referenced by loadASConfig(), and updateSendProcess().

RoutingTableEntryVector inet::bgp::BGPRouting::_BGPRoutingTable
private
SessionID inet::bgp::BGPRouting::_currSessionId = 0
private
IInterfaceTable* inet::bgp::BGPRouting::_inft = nullptr
private
ASID inet::bgp::BGPRouting::_myAS = 0
private
RoutingTableEntryVector inet::bgp::BGPRouting::_prefixListIN
private

Referenced by decisionProcess(), and loadASConfig().

RoutingTableEntryVector inet::bgp::BGPRouting::_prefixListINOUT
private

Referenced by loadASConfig(), and ~BGPRouting().

RoutingTableEntryVector inet::bgp::BGPRouting::_prefixListOUT
private

Referenced by loadASConfig(), and updateSendProcess().

TCPSocketMap inet::bgp::BGPRouting::_socketMap
private
const int inet::bgp::BGPRouting::BGP_TCP_CONNECT_CONFIRM = 72
staticprivate
const int inet::bgp::BGPRouting::BGP_TCP_CONNECT_FAILED = 73
staticprivate
const int inet::bgp::BGPRouting::BGP_TCP_CONNECT_OPEN_RCV = 74
staticprivate
const int inet::bgp::BGPRouting::BGP_TCP_CONNECT_VALID = 71
staticprivate
const int inet::bgp::BGPRouting::BGP_TCP_KEEP_ALIVE_RCV = 75
staticprivate

The documentation for this class was generated from the following files: