Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions examples/bgpv4/BgpLifecycle/BGPConfig.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<BGPConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="BGP.xsd">

<TimerParams>
<connectRetryTime> 120 </connectRetryTime>
<holdTime> 180 </holdTime>
<keepAliveTime> 60 </keepAliveTime>
<startDelay> 2 </startDelay>
</TimerParams>

<AS id="65324">
<!--router A-->
<Router interAddr="192.168.1.254"/>
</AS>

<AS id="65248">
<!--router B-->
<Router interAddr="192.168.2.254"/>
</AS>

<Session id="1">
<Router exterAddr="10.10.10.1"/> <!--router A-->
<Router exterAddr="10.10.10.2"/> <!--router B-->
</Session>

</BGPConfig>

10 changes: 10 additions & 0 deletions examples/bgpv4/BgpLifecycle/IPv4Config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<config>
<interface hosts='A' names='ppp0' address='10.10.10.1' netmask='255.255.255.0' mtu='1500' metric='1'/>
<interface hosts='A' names='eth0' address='192.168.1.254' netmask='255.255.255.0' mtu='1500' metric='1'/>
<interface hosts='B' names='ppp0' address='10.10.10.2' netmask='255.255.255.0'/>
<interface hosts='B' names='eth0' address='192.168.2.254' netmask='255.255.255.0' mtu='1500' metric='1'/>
<interface hosts='H1' names='eth0' address='192.168.1.1' netmask='255.255.255.0' mtu='1500' metric='1'/>
<interface hosts='H2' names='eth0' address='192.168.2.1' netmask='255.255.255.0' mtu='1500' metric='1'/>
<route hosts='H*' destination='*' netmask='*' interface='eth0'/>
</config>

70 changes: 70 additions & 0 deletions examples/bgpv4/BgpLifecycle/Network.ned
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package inet.examples.bgpv4.BgpLifecycle;

import inet.common.misc.ThruputMeteringChannel;
import inet.common.scenario.ScenarioManager;
import inet.networklayer.configurator.ipv4.Ipv4NetworkConfigurator;
import inet.node.bgp.BgpRouter;
import inet.node.inet.StandardHost;
import inet.visualizer.canvas.integrated.IntegratedCanvasVisualizer;

network BgpNetwork
{
types:
channel LINK_100 extends ThruputMeteringChannel
{
parameters:
delay = 50us;
datarate = 100Mbps;
displayAsTooltip = true;
thruputDisplayFormat = "#N";
}
submodules:
visualizer: IntegratedCanvasVisualizer {
parameters:
@display("p=100,100;is=s");
}
configurator: Ipv4NetworkConfigurator {
parameters:
@display("p=100,200;is=s");
config = xmldoc("IPv4Config.xml");
addStaticRoutes = false;
addDefaultRoutes = false;
addSubnetRoutes = false;
}
scenarioManager: ScenarioManager {
parameters:
@display("p=100,300;is=s");
}
A: BgpRouter {
parameters:
hasStatus = true;
@display("p=400,100");
gates:
pppg[1];
ethg[1];
}
B: BgpRouter {
parameters:
hasStatus = true;
@display("p=550,100");
gates:
pppg[1];
ethg[1];
}
H1: StandardHost {
parameters:
@display("p=250,100;i=device/laptop");
gates:
ethg[1];
}
H2: StandardHost {
parameters:
@display("p=700,100;i=device/laptop");
gates:
ethg[1];
}
connections:
H1.ethg[0] <--> LINK_100 <--> A.ethg[0];
A.pppg[0] <--> LINK_100 <--> B.pppg[0];
B.ethg[0] <--> LINK_100 <--> H2.ethg[0];
}
22 changes: 22 additions & 0 deletions examples/bgpv4/BgpLifecycle/OSPFConfig.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0"?>
<OSPFASConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="OSPF.xsd">

<!-- Areas -->
<Area id="0.0.0.1">
<AddressRange address="H1" mask="H1" status="Advertise" />
</Area>
<Area id="0.0.0.2">
<AddressRange address="H2" mask="H2" status="Advertise" />
</Area>

<!-- Routers -->
<Router name="A" RFC1583Compatible="true">
<BroadcastInterface ifName="eth0" areaID="0.0.0.1" interfaceOutputCost="1" routerPriority="1" />
</Router>

<Router name="B" RFC1583Compatible="true">
<BroadcastInterface ifName="eth0" areaID="0.0.0.2" interfaceOutputCost="1" routerPriority="1" />
</Router>

</OSPFASConfig>

Binary file added examples/bgpv4/BgpLifecycle/network.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 53 additions & 0 deletions examples/bgpv4/BgpLifecycle/omnetpp.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
[General]
description = "BGP lifecycle operations"
network = BgpNetwork
sim-time-limit = 900s
output-scalar-file = results.sca
output-scalar-precision = 5

**.app[0].**.scalar-recording = true
**.bgp.**.scalar-recording = true
**.scalar-recording = false
**.vector-recording = false

# NIC configuration
**.eth[*].queue.packetCapacity = 100

#tcp settings
**.tcp.typename = "Tcp"
**.tcp.mss = 1024
**.tcp.advertisedWindow = 14336
**.tcp.tcpAlgorithmClass = "TcpReno"

# OSPF configuration
**.ospfConfig = xmldoc("OSPFConfig.xml")

# bgp settings
**.bgpConfig = xmldoc("BGPConfig.xml")
**.redistributeOspf = "O IA"

# Visualizer settings
*.visualizer.interfaceTableVisualizer.displayInterfaceTables = true

# UDPApp parameters
*.H*.numApps = 1
**.app[0].messageLength = 32 bytes
**.app[0].sendInterval = 10s
**.app[0].startTime = 80s
**.app[0].destPort = 5678

**.H1.app[0].typename = "UdpBasicApp"
**.H1.app[0].localPort = 1234
**.H1.app[0].destAddresses = "192.168.2.1"

**.H2.app[0].typename="UdpSink"
**.H2.app[0].localPort = 5678

# Lifecycle operations: allow BGP sessions to establish, stop router A
# gracefully, restart it, then crash it later in the run.
*.scenarioManager.script = xml( \
"<script>\n" + \
"<at t='120s'><shutdown module='A'/></at>\n" + \
"<at t='300s'><startup module='A'/></at>\n" + \
"<at t='600s'><crash module='A'/></at>\n" + \
"</script>")
93 changes: 62 additions & 31 deletions src/inet/routing/bgpv4/Bgp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "inet/routing/bgpv4/Bgp.h"

#include "inet/common/ModuleAccess.h"
#include "inet/common/lifecycle/NodeStatus.h"
#include "inet/routing/bgpv4/BgpConfigReader.h"
#include "inet/routing/bgpv4/BgpSession.h"

Expand All @@ -28,62 +27,95 @@ Bgp::~Bgp()

void Bgp::initialize(int stage)
{
SimpleModule::initialize(stage);
RoutingProtocolBase::initialize(stage);

if (stage == INITSTAGE_LOCAL) {
ift.reference(this, "interfaceTableModule", true);
rt.reference(this, "routingTableModule", true);

startupTimer = new cMessage("BGP-startup");

WATCH(isUp);
}
else if (stage == INITSTAGE_ROUTING_PROTOCOLS) { // interfaces and static routes are already initialized
cModule *node = findContainingNode(this);
NodeStatus *nodeStatus = node ? check_and_cast_nullable<NodeStatus *>(node->getSubmodule("status")) : nullptr;
isUp = !nodeStatus || nodeStatus->getState() == NodeStatus::UP;
if (isUp) {
simtime_t startupTime = par("startupTime");
if (startupTime == 0)
createBgpRouter();
else
scheduleAfter(startupTime, startupTimer);
}
}
}

void Bgp::finish()
{
if (!isUp) {
if (!bgpRouter) {
EV_ERROR << "Protocol is turned off. \n";
return;
}

bgpRouter->recordStatistics();
}

void Bgp::handleMessage(cMessage *msg)
void Bgp::handleMessageWhenUp(cMessage *msg)
{
if (!isUp) {
if (msg->isSelfMessage())
throw cRuntimeError("Model error: self msg '%s' received when protocol is down", msg->getName());
EV_ERROR << "Protocol is turned off, dropping '" << msg->getName() << "' message\n";
delete msg;
return;
if (msg == startupTimer)
createBgpRouter();
else {
if (!bgpRouter) {
if (msg->isSelfMessage())
throw cRuntimeError("Model error: self msg '%s' received before BGP startup", msg->getName());
EV_WARN << "BGP has not started yet, dropping '" << msg->getName() << "' message\n";
delete msg;
}
else if (msg->isSelfMessage()) // BGP level
handleTimer(msg);
else if (!strcmp(msg->getArrivalGate()->getName(), "socketIn")) // TCP level
bgpRouter->processMessageFromTCP(msg);
else
delete msg;
}
}

if (msg == startupTimer)
void Bgp::handleStartOperation(LifecycleOperation *operation)
{
startBgp();
}

void Bgp::handleStopOperation(LifecycleOperation *operation)
{
stopBgp(false);
}

void Bgp::handleCrashOperation(LifecycleOperation *operation)
{
stopBgp(true);
}

void Bgp::startBgp()
{
ASSERT(bgpRouter == nullptr);
simtime_t startupTime = par("startupTime");
if (startupTime == 0)
createBgpRouter();
else if (msg->isSelfMessage()) // BGP level
handleTimer(msg);
else if (!strcmp(msg->getArrivalGate()->getName(), "socketIn")) // TCP level
bgpRouter->processMessageFromTCP(msg);
else
delete msg;
scheduleAfter(startupTime, startupTimer);
}

void Bgp::stopBgp(bool abort)
{
cancelEvent(startupTimer);
removeBgpRoutes();
if (bgpRouter)
bgpRouter->closeSessions(abort);
delete bgpRouter;
bgpRouter = nullptr;
}

void Bgp::removeBgpRoutes()
{
for (int i = rt->getNumRoutes() - 1; i >= 0; i--) {
Ipv4Route *route = rt->getRoute(i);
if (route->getSourceType() == IRoute::BGP) {
EV_INFO << "Removing BGP route " << route->str() << endl;
rt->deleteRoute(route);
}
}
}

void Bgp::createBgpRouter()
{
ASSERT(bgpRouter == nullptr);
bgpRouter = new BgpRouter(this, ift, rt);

// read BGP configuration
Expand Down Expand Up @@ -128,4 +160,3 @@ void Bgp::handleTimer(cMessage *timer)

} // namespace bgp
} // namespace inet

15 changes: 9 additions & 6 deletions src/inet/routing/bgpv4/Bgp.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
#ifndef __INET_BGP_H
#define __INET_BGP_H

#include "inet/common/SimpleModule.h"
#include "inet/common/lifecycle/LifecycleUnsupported.h"
#include "inet/networklayer/contract/ipv4/Ipv4Address.h"
#include "inet/networklayer/ipv4/Ipv4InterfaceData.h"
#include "inet/routing/base/RoutingProtocolBase.h"
#include "inet/routing/bgpv4/BgpCommon.h"
#include "inet/routing/bgpv4/BgpRouter.h"
#include "inet/routing/bgpv4/bgpmessage/BgpHeader_m.h"
Expand All @@ -19,12 +18,11 @@ namespace inet {

namespace bgp {

class INET_API Bgp : public SimpleModule, protected cListener, public LifecycleUnsupported
class INET_API Bgp : public RoutingProtocolBase, protected cListener
{
private:
ModuleRefByPar<IIpv4RoutingTable> rt;
ModuleRefByPar<IInterfaceTable> ift;
bool isUp = false;
BgpRouter *bgpRouter = nullptr; // data structure to fill in
cMessage *startupTimer = nullptr; // timer for delayed startup

Expand All @@ -35,7 +33,13 @@ class INET_API Bgp : public SimpleModule, protected cListener, public LifecycleU
protected:
virtual int numInitStages() const override { return NUM_INIT_STAGES; }
virtual void initialize(int stage) override;
virtual void handleMessage(cMessage *msg) override;
virtual void handleMessageWhenUp(cMessage *msg) override;
virtual void handleStartOperation(LifecycleOperation *operation) override;
virtual void handleStopOperation(LifecycleOperation *operation) override;
virtual void handleCrashOperation(LifecycleOperation *operation) override;
void startBgp();
void stopBgp(bool abort);
void removeBgpRoutes();
void createBgpRouter();
void handleTimer(cMessage *timer);
virtual void finish() override;
Expand All @@ -46,4 +50,3 @@ class INET_API Bgp : public SimpleModule, protected cListener, public LifecycleU
} // namespace inet

#endif

Loading