|
INET Framework for OMNeT++/OMNEST
|
#include <BgpConfigReader.h>
|
| std::vector< const char * > | findInternalPeers (cXMLElementList &ASConfig) |
| |
| void | loadASConfig (cXMLElementList &ASConfig) |
| |
| void | loadEbgpSessionConfig (cXMLElementList &ASConfig, cXMLElementList &sessionList, simtime_t *delayTab) |
| |
| AsId | findMyAS (cXMLElementList &ASList, int &outRouterPosition) |
| |
| void | loadTimerConfig (cXMLElementList &timerConfig, simtime_t *delayTab) |
| |
| int | isInInterfaceTable (IInterfaceTable *ifTable, Ipv4Address addr) |
| |
| int | isInInterfaceTable (IInterfaceTable *ifTable, std::string ifName) |
| |
| unsigned int | calculateStartDelay (int rtListSize, unsigned char rtPosition, unsigned char rtPeerPosition) |
| |
| bool | getBoolAttrOrPar (const cXMLElement &ifConfig, const char *name) const |
| |
| int | getIntAttrOrPar (const cXMLElement &ifConfig, const char *name) const |
| |
| const char * | getStrAttrOrPar (const cXMLElement &ifConfig, const char *name) const |
| |
◆ BgpConfigReader()
| inet::bgp::BgpConfigReader::BgpConfigReader |
( |
cModule * |
bgpModule, |
|
|
IInterfaceTable * |
ift |
|
) |
| |
◆ ~BgpConfigReader()
| virtual inet::bgp::BgpConfigReader::~BgpConfigReader |
( |
| ) |
|
|
inlinevirtual |
◆ calculateStartDelay()
| unsigned int inet::bgp::BgpConfigReader::calculateStartDelay |
( |
int |
rtListSize, |
|
|
unsigned char |
rtPosition, |
|
|
unsigned char |
rtPeerPosition |
|
) |
| |
|
private |
273 unsigned int startDelay = 0;
274 if (rtPeerPosition == 1) {
275 if (rtPosition == 1) {
279 startDelay = (rtPosition - 1) * 2;
284 if (rtPosition < rtPeerPosition) {
287 else if (rtPosition > rtPeerPosition) {
288 startDelay = (rtListSize - 1) * 2 - 2 * (rtPeerPosition - 2);
291 startDelay = (rtListSize - 1) * 2 + 1;
Referenced by loadConfigFromXML().
◆ findInternalPeers()
| std::vector< const char * > inet::bgp::BgpConfigReader::findInternalPeers |
( |
cXMLElementList & |
ASConfig | ) |
|
|
private |
182 std::vector<const char *> routerInSameASList;
183 for (
auto& elem : ASConfig) {
184 std::string nodeName = elem->getTagName();
185 if (nodeName ==
"Router") {
186 Ipv4Address internalAddr = Ipv4Address(elem->getAttribute(
"interAddr"));
188 routerInSameASList.push_back(elem->getAttribute(
"interAddr"));
193 return routerInSameASList;
Referenced by loadConfigFromXML().
◆ findMyAS()
| AsId inet::bgp::BgpConfigReader::findMyAS |
( |
cXMLElementList & |
ASList, |
|
|
int & |
outRouterPosition |
|
) |
| |
|
private |
101 for (
auto& elem : asList) {
102 cXMLElementList routerList = (elem)->getChildrenByTagName(
"Router");
103 outRouterPosition = 1;
104 for (
auto& routerList_routerListIt : routerList) {
105 Ipv4Address routerAddr = Ipv4Address((routerList_routerListIt)->getAttribute(
"interAddr"));
108 return atoi((routerList_routerListIt)->getParentNode()->getAttribute(
"id"));
Referenced by loadConfigFromXML().
◆ getBoolAttrOrPar()
| bool inet::bgp::BgpConfigReader::getBoolAttrOrPar |
( |
const cXMLElement & |
ifConfig, |
|
|
const char * |
name |
|
) |
| const |
|
private |
298 const char *attrStr = ifConfig.getAttribute(name);
299 if (attrStr && *attrStr) {
300 if (strcmp(attrStr,
"true") == 0 || strcmp(attrStr,
"1") == 0)
302 if (strcmp(attrStr,
"false") == 0 || strcmp(attrStr,
"0") == 0)
304 throw cRuntimeError(
"Invalid boolean attribute %s = '%s' at %s", name, attrStr, ifConfig.getSourceLocation());
Referenced by loadASConfig(), and loadEbgpSessionConfig().
◆ getIntAttrOrPar()
| int inet::bgp::BgpConfigReader::getIntAttrOrPar |
( |
const cXMLElement & |
ifConfig, |
|
|
const char * |
name |
|
) |
| const |
|
private |
◆ getStrAttrOrPar()
| const char * inet::bgp::BgpConfigReader::getStrAttrOrPar |
( |
const cXMLElement & |
ifConfig, |
|
|
const char * |
name |
|
) |
| const |
|
private |
319 const char *attrStr = ifConfig.getAttribute(name);
320 if (attrStr && *attrStr)
Referenced by loadASConfig().
◆ isInInterfaceTable() [1/2]
◆ isInInterfaceTable() [2/2]
| int inet::bgp::BgpConfigReader::isInInterfaceTable |
( |
IInterfaceTable * |
ifTable, |
|
|
std::string |
ifName |
|
) |
| |
|
private |
263 for (
int i = 0; i < ifTable->getNumInterfaces(); i++) {
264 if (std::string(ifTable->getInterface(i)->getInterfaceName()) == ifName) {
◆ loadASConfig()
| void inet::bgp::BgpConfigReader::loadASConfig |
( |
cXMLElementList & |
ASConfig | ) |
|
|
private |
201 for (
auto& elem : ASConfig) {
202 std::string nodeName = elem->getTagName();
203 if (nodeName ==
"Router") {
204 Ipv4Address internalAddr = Ipv4Address(elem->getAttribute(
"interAddr"));
210 for (
auto& entry : elem->getChildren()) {
211 std::string nodeName = entry->getTagName();
212 if (nodeName ==
"Network") {
213 const char *address = entry->getAttribute(
"address");
214 if (address && *address)
217 throw cRuntimeError(
"BGP Error: attribute 'address' is mandatory in 'Network'");
219 else if (nodeName ==
"Neighbor") {
220 const char *peer = entry->getAttribute(
"address");
229 throw cRuntimeError(
"BGP Error: attribute 'address' is mandatory in 'Neighbor'");
232 throw cRuntimeError(
"BGP Error: attribute '%s' is invalid in 'Router'", nodeName.c_str());
236 else if (nodeName ==
"DenyRoute" || nodeName ==
"DenyRouteIN" || nodeName ==
"DenyRouteOUT") {
237 BgpRoutingTableEntry *entry =
new BgpRoutingTableEntry();
238 entry->setDestination(Ipv4Address((elem)->getAttribute(
"Address")));
239 entry->setNetmask(Ipv4Address((elem)->getAttribute(
"Netmask")));
242 else if (nodeName ==
"DenyAS" || nodeName ==
"DenyASIN" || nodeName ==
"DenyASOUT") {
243 AsId ASCur = atoi((elem)->getNodeValue());
247 throw cRuntimeError(
"BGP Error: unknown element named '%s' for AS %u", nodeName.c_str(),
bgpRouter->
getAsId());
Referenced by loadConfigFromXML().
◆ loadConfigFromXML()
| void inet::bgp::BgpConfigReader::loadConfigFromXML |
( |
cXMLElement * |
bgpConfig, |
|
|
BgpRouter * |
bgpRouter |
|
) |
| |
25 if (strcmp(bgpConfig->getTagName(),
"BGPConfig"))
26 throw cRuntimeError(
"Cannot read BGP configuration, unaccepted '%s' node at %s", bgpConfig->getTagName(), bgpConfig->getSourceLocation());
29 cXMLElement *paramNode = bgpConfig->getElementByPath(
"TimerParams");
30 if (paramNode ==
nullptr)
31 throw cRuntimeError(
"BGP Error: No configuration for BGP timer parameters");
32 cXMLElementList timerConfig = paramNode->getChildren();
37 cXMLElementList ASList = bgpConfig->getElementsByTagName(
"AS");
41 throw cRuntimeError(
"BGP Error: No AS configuration for Router ID: %s",
bgpRouter->
getRouterId().
str().c_str());
47 sprintf(ASXPath,
"AS[@id='%d']", myAsId);
48 cXMLElement *ASNode = bgpConfig->getElementByPath(ASXPath);
49 if (ASNode ==
nullptr)
50 throw cRuntimeError(
"BGP Error: No configuration for AS ID: %d", myAsId);
51 cXMLElementList ASConfig = ASNode->getChildren();
54 cXMLElementList sessionList = bgpConfig->getElementsByTagName(
"Session");
55 simtime_t saveStartDelay = delayTab[3];
57 delayTab[3] = saveStartDelay;
63 if (routerInSameASList.size()) {
64 unsigned int routerPeerPosition = 1;
65 delayTab[3] += sessionList.size() * 2;
66 for (
auto it = routerInSameASList.begin(); it != routerInSameASList.end(); it++, routerPeerPosition++) {
68 delayTab[3] +=
calculateStartDelay(routerInSameASList.size(), routerPosition, routerPeerPosition);
Referenced by inet::bgp::Bgp::createBgpRouter().
◆ loadEbgpSessionConfig()
| void inet::bgp::BgpConfigReader::loadEbgpSessionConfig |
( |
cXMLElementList & |
ASConfig, |
|
|
cXMLElementList & |
sessionList, |
|
|
simtime_t * |
delayTab |
|
) |
| |
|
private |
119 simtime_t saveStartDelay = delayTab[3];
120 for (
auto sessionListIt = sessionList.begin(); sessionListIt != sessionList.end(); sessionListIt++, delayTab[3] = saveStartDelay) {
121 auto numRouters = (*sessionListIt)->getChildren();
122 if (numRouters.size() != 2)
123 throw cRuntimeError(
"BGP Error: Number of routers is invalid for session ID : %s", (*sessionListIt)->getAttribute(
"id"));
125 Ipv4Address routerAddr1 = Ipv4Address((*sessionListIt)->getFirstChild()->getAttribute(
"exterAddr"));
126 Ipv4Address routerAddr2 = Ipv4Address((*sessionListIt)->getLastChild()->getAttribute(
"exterAddr"));
130 Ipv4Address peerAddr;
133 peerAddr = routerAddr2;
134 myAddr = routerAddr1;
135 delayTab[3] += atoi((*sessionListIt)->getAttribute(
"id"));
138 peerAddr = routerAddr1;
139 myAddr = routerAddr2;
140 delayTab[3] += atoi((*sessionListIt)->getAttribute(
"id")) +
bgpModule->par(
"ExternalPeerStartDelayOffset").doubleValue();
143 if (peerAddr.isUnspecified())
144 throw cRuntimeError(
"BGP Error: No valid external address for session ID : %s", (*sessionListIt)->getAttribute(
"id"));
146 SessionInfo externalInfo;
148 externalInfo.myAddr = myAddr;
149 externalInfo.checkConnection =
bgpModule->par(
"connectedCheck").boolValue();
150 externalInfo.ebgpMultihop =
bgpModule->par(
"ebgpMultihop").intValue();
151 if (externalInfo.ebgpMultihop < 1)
152 throw cRuntimeError(
"BGP Error: ebgpMultihop parameter must be >= 1");
153 else if (externalInfo.ebgpMultihop > 1)
154 externalInfo.checkConnection =
false;
156 for (
auto& elem : ASConfig) {
157 if (std::string(elem->getTagName()) ==
"Router") {
159 for (
auto& entry : elem->getChildren()) {
160 if (std::string(entry->getTagName()) ==
"Neighbor") {
161 const char *peer = entry->getAttribute(
"address");
162 if (peer && *peer && peerAddr.equals(Ipv4Address(peer))) {
165 if (externalInfo.ebgpMultihop > 1)
166 externalInfo.checkConnection =
false;
Referenced by loadConfigFromXML().
◆ loadTimerConfig()
| void inet::bgp::BgpConfigReader::loadTimerConfig |
( |
cXMLElementList & |
timerConfig, |
|
|
simtime_t * |
delayTab |
|
) |
| |
|
private |
80 for (
auto& elem : timerConfig) {
81 std::string nodeName = (elem)->getTagName();
82 if (nodeName ==
"connectRetryTime") {
83 delayTab[0] = (double)atoi((elem)->getNodeValue());
85 else if (nodeName ==
"holdTime") {
86 delayTab[1] = (double)atoi((elem)->getNodeValue());
88 else if (nodeName ==
"keepAliveTime") {
89 delayTab[2] = (double)atoi((elem)->getNodeValue());
91 else if (nodeName ==
"startDelay") {
92 delayTab[3] = (double)atoi((elem)->getNodeValue());
Referenced by loadConfigFromXML().
◆ bgpModule
| cModule* inet::bgp::BgpConfigReader::bgpModule = nullptr |
|
private |
◆ bgpRouter
| BgpRouter* inet::bgp::BgpConfigReader::bgpRouter = nullptr |
|
private |
◆ ift
The documentation for this class was generated from the following files:
unsigned long SessionId
Definition: BgpCommon.h:52
void setSocketListen(SessionId id)
Definition: BgpRouter.cc:143
void setRedistributeOspf(std::string x)
Definition: BgpRouter.cc:254
std::vector< const char * > findInternalPeers(cXMLElementList &ASConfig)
Definition: BgpConfigReader.cc:180
void setInternalAddress(Ipv4Address x)
Definition: BgpRouter.h:72
void setRedistributeInternal(bool x)
Definition: BgpRouter.h:74
const InterfaceProtocolData * getProtocolData(int index) const
Returns the protocol data at the given index.
Definition: NetworkInterface.h:287
int getIntAttrOrPar(const cXMLElement &ifConfig, const char *name) const
Definition: BgpConfigReader.cc:309
bool getBoolAttrOrPar(const cXMLElement &ifConfig, const char *name) const
Definition: BgpConfigReader.cc:296
void setDefaultConfig()
Definition: BgpRouter.cc:149
void loadEbgpSessionConfig(cXMLElementList &ASConfig, cXMLElementList &sessionList, simtime_t *delayTab)
Definition: BgpConfigReader.cc:117
int isInInterfaceTable(IInterfaceTable *ifTable, Ipv4Address addr)
Definition: BgpConfigReader.cc:251
cModule * bgpModule
Definition: BgpConfigReader.h:24
void setRedistributeRip(bool x)
Definition: BgpRouter.h:76
SessionId createIbgpSession(const char *peerAddr)
Definition: BgpRouter.cc:81
void addToAsList(std::string nodeName, AsId id)
Definition: BgpRouter.cc:212
void setAsId(AsId myAsId)
Definition: BgpRouter.h:65
BgpRouter * bgpRouter
Definition: BgpConfigReader.h:26
void setTimer(SessionId id, simtime_t *delayTab)
Definition: BgpRouter.cc:138
unsigned int calculateStartDelay(int rtListSize, unsigned char rtPosition, unsigned char rtPeerPosition)
Definition: BgpConfigReader.cc:271
AsId findMyAS(cXMLElementList &ASList, int &outRouterPosition)
Definition: BgpConfigReader.cc:97
void addToAdvertiseList(Ipv4Address address)
Definition: BgpRouter.cc:168
AsId getAsId()
Definition: BgpRouter.h:66
std::string str(bool printUnspec=true) const
Returns the string representation of the address (e.g.
Definition: Ipv4Address.cc:98
SessionId createEbgpSession(const char *peerAddr, SessionInfo &externalInfo)
Definition: BgpRouter.cc:103
void setNextHopSelf(Ipv4Address peer, bool nextHopSelf)
Definition: BgpRouter.cc:226
void loadASConfig(cXMLElementList &ASConfig)
Definition: BgpConfigReader.cc:196
virtual int getNumInterfaces() const =0
Returns the number of interfaces.
IInterfaceTable * ift
Definition: BgpConfigReader.h:25
const unsigned char NB_TIMERS
Definition: BgpCommon.h:27
RouterId getRouterId()
Definition: BgpRouter.h:64
virtual NetworkInterface * getInterface(int pos) const =0
Returns the NetworkInterface specified by an index 0..numInterfaces-1.
unsigned short AsId
Definition: BgpCommon.h:51
const char * getStrAttrOrPar(const cXMLElement &ifConfig, const char *name) const
Definition: BgpConfigReader.cc:317
void setLocalPreference(Ipv4Address peer, int localPref)
Definition: BgpRouter.cc:240
void loadTimerConfig(cXMLElementList &timerConfig, simtime_t *delayTab)
Definition: BgpConfigReader.cc:78
void addToPrefixList(std::string nodeName, BgpRoutingTableEntry *entry)
Definition: BgpRouter.cc:195