connecting a router and a switch

489 views
Skip to first unread message

gist extra

unread,
Nov 9, 2016, 4:17:58 AM11/9/16
to ns-3-users
i am looking at connecting a router and a switch together both i don't know which link is best to connect it with, also i am looking at sending continous data from different nodes to a server on a topology i am creating, please i would appreciate if someone could help me with this.

Tommaso Pecorella

unread,
Nov 9, 2016, 1:27:23 PM11/9/16
to ns-3-users
Have you read the tutorial ?

T.

gist extra

unread,
Nov 18, 2016, 4:42:53 AM11/18/16
to ns-3-users
thank you sir for your reply,  i have read the tutorial and i have tried my best ;

this is the code i came up with for my topology but i have some problems, i am trying to see if i would be able to get a VRRP protocol for my network but is seems NS3 those not have, i don't know if there is a way to move packet in such a way if one of the router is over loaded the switch i created should be able to switch to the next router (am trying to create a redundancy to by some time in a ddos attack)

the topology i want to build is attached to this, please your help will be highly welcomed.

here is the code i have been able to write for the topology





#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/csma-module.h"
#include "ns3/wifi-module.h"
#include "ns3/mobility-module.h"
#include "ns3/bridge-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-module.h"

using namespace ns3;

NS_LOG_COMPONENT_DEFINE ("MrAmadiPhdWork");

int
main (int argc, char *argv[])
{

 uint32_t nWifi = 5;
 bool tracing = false;

CommandLine cmd;
bool verbose = true;
cmd.AddValue ("nWifi", "Number of wifi STA devices", nWifi);
cmd.AddValue ("verbose", "Tell echo applications to log if true", verbose);

cmd.Parse (argc,argv);

if (nWifi > 250)
    {
      std::cout << "Too many wifi nodes, no more than 250 each." << std::endl;
      return 1;
    }
 if (verbose)
    {
      LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
      LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
    }


  NodeContainer wifiApNode;
  wifiApNode.Create (1);

  NodeContainer FireSeverNode;
  FireSeverNodes.Create(2);


  NS_LOG_INFO ("INFO: Create nodes majors.");
  Ptr<Node> tr  = CreateObject<Node> ();  //master  router
  Ptr<Node> br  = CreateObject<Node> ();  //slave router
  Ptr<Node> Fst  = CreateObject<Node> ();  // switch connection form the access point
  Ptr<Node> Lst  = CreateObject<Node> ();  // switch connection from both router to the firwall

 // ----------------------------------------------------------------------
  // Give the nodes names
  // ----------------------------------------------------------------------

  Names::Add ("tr",  tr);
  Names::Add ("br",  br);
  Names::Add ("Fst", Fst);
  Names::Add ("Lst", Lst);

 // Builing link from the router to the

  CsmaHelper csma;
  csma.SetChannelAttribute ("DataRate", StringValue ("100Mbps"));
  csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (6560)));
 
  NS_LOG_INFO ("Creating Point-To-Point Link");

  PointToPointHelper pointToPoint;
  pointToPoint.SetDeviceAttribute  ("DataRate", StringValue ("5Mbps"));
  pointToPoint.SetChannelAttribute ("Delay",    StringValue ("2ms"));

 // -------------------------------------------------------------------------
// Now connecting the routers and the switches together with the access point
// --------------------------------------------------------------------------

// Point-Point connection switch connection from the AP
 

  NetDeviceContainer p2pDevices;
  p2pDevices = pointToPoint.Install (NodeContainer (wifiApNode.Get (0),  Fst));

// CSMA connection between first switch and the two routers
  NetDeviceContainer link_Fst_tr   = csma.Install (NodeContainer (Fst,  tr));
  NetDeviceContainer link_Fst_br   = csma.Install (NodeContainer (Fst,  br));

// CSMA connection between two routers and the last switch
  NetDeviceContainer link_tr_Lst   = csma.Install (NodeContainer (tr,  Lst));
  NetDeviceContainer link_br_Lst   = csma.Install (NodeContainer (br,  Lst));

NodeContainer fwNode = FireSeverNodes.Get(0);
// CSMA connection from the last switch to the firewall
  NetDeviceContainer link_Lst_Fw   = csma.Install (NodeContainer (Lst,  fwNode.Get(0)));

NodeContainer serverNode = FireSeverNodes.Get(1);
// CSMA connection from firewall to the server
  NetDeviceContainer link_Fw_Server   = csma.Install (NodeContainer (fwNode.Get(0),  serverNode.Get(0)));

// ======================================================================
// Manually create the list of NetDevices for each switch
// ----------------------------------------------------------------------

// First Switch NetDevice
  NetDeviceContainer Fstnd;
  Fstnd.Add (p2pDevices.Get (1));
  Fstnd.Add (link_Fst_tr.Get (0));
  Fstnd.Add (link_Fst_br.Get (0));

// Last Switch NetDevice
  NetDeviceContainer Lstnd;
  Lstnd.Add (link_tr_Lst.Get (1));
  Lstnd.Add (link_br_Lst.Get (1));
  Lstnd.Add (link_Fst_Fw.Get (0));


  NodeContainer wifiStaNodes;
  wifiStaNodes.Create (nWifi);
 
 
  YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
  YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();
  phy.SetChannel (channel.Create ());

  WifiHelper wifi;
  wifi.SetRemoteStationManager ("ns3::AarfWifiManager");

  WifiMacHelper mac;
  Ssid ssid = Ssid ("ns-3-ssid");
  mac.SetType ("ns3::StaWifiMac",
               "Ssid", SsidValue (ssid),
               "ActiveProbing", BooleanValue (false));

  NetDeviceContainer staDevices;
  staDevices = wifi.Install (phy, mac, wifiStaNodes);

  mac.SetType ("ns3::ApWifiMac",
               "Ssid", SsidValue (ssid));

  NetDeviceContainer apDevices;
  apDevices = wifi.Install (phy, mac, wifiApNode);

  MobilityHelper mobility;

  mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
                                 "MinX", DoubleValue (0.0),
                                 "MinY", DoubleValue (0.0),
                                 "DeltaX", DoubleValue (5.0),
                                 "DeltaY", DoubleValue (10.0),
                                 "GridWidth", UintegerValue (3),
                                 "LayoutType", StringValue ("RowFirst"));

  mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
                             "Bounds", RectangleValue (Rectangle (-50, 50, -50, 50)));
  mobility.Install (wifiStaNodes);

  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
  mobility.Install (wifiApNode);

 
  InternetStackHelper stack;
  stack.Install (wifiApNode);
  stack.Install (wifiStaNodes);

  NS_LOG_INFO ("L3: Install the ns3 IP stack on routers.");
  NodeContainer routerNodes (tr, br);
  stack.Install (routerNodes);

  NS_LOG_INFO ("Install the ns3 IP stack on the firewall and server");
  NodeContainer fsNodes (fwNode.Get(0),  serverNode.Get(0));
  stack.Install (fsNodes);

  BridgeHelper bridge;

  bridge.Install (Fst, Fstnd);
  bridge.Install (Lst, Lstnd);

//---------------------------------------------------------------------------
// Place the access point and the wifistation nodes in the same nodecontainer
//---------------------------------------------------------------------------

  NodeDeviceContainer
  Ipv4AddressHelper address;

  address.SetBase ("10.1.1.0", "255.255.255.0");
  address.Assign (staDevices);
  address.Assign (apDevices);

// ----------------------------------------------------------------------
  // Assign IP address to the individual routers
  // ----------------------------------------------------------------------
  NS_LOG_INFO ("L3: Assign IP Addresses to the DMZ routers.");

  NetDeviceContainer routerIpDevices;       
  botLanIpDevices.Add (link_Fst_tr.Get (1)); 
  botLanIpDevices.Add (link_Fst_br.Get (1)); 
 
  address.SetBase ("192.168.2.0", "255.255.255.0");
  address.Assign  (routerIpDevices);

//-------------------------------------------------------------------------
// Assign IP address to the firewall node and the server node
//--------------------------------------------------------------------------
  address.SetBase ("10.1.2.0", "255.255.255.0");
  address.Assign (link_Fw_Server)


  // ======================================================================
  // Calculate and populate routing tables
  // ----------------------------------------------------------------------
  NS_LOG_INFO ("L3: Populate routing tables.");
  Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
IMG_20161118_103917.jpg

Tommaso Pecorella

unread,
Nov 19, 2016, 8:04:52 PM11/19/16
to ns-3-users
Hi,

ok, you did miss the posting guidelines part where it's "suggested" to not copy-paste the code (you have to attack it to the message).

About how to simulate your topology, you're missing one important point: how do the switch knows when a router is not anymore working ?
Your topology could work, but the switch will never "switch" from a router to the next one.

Moreover, even if it could work, how the other nodes are going to know that the router to use is the new one ? That's rerouting, and it's not as easy as redirecting traffic over a different path. Unless your router is a perfect mirror of the first one, but in that case you'd have IP duplication.

Summarizing, it's not a matter of how to make it work on ns-3, it's a problem of how to make it work at all.

T.


On Friday, November 18, 2016 at 10:42:53 AM UTC+1, gist extra wrote:
thank you sir for your reply,  i have read the tutorial and i have tried my best ;

this is the code i came up with for my topology but i have some problems, i am trying to see if i would be able to get a VRRP protocol for my network but is seems NS3 those not have, i don't know if there is a way to move packet in such a way if one of the router is over loaded the switch i created should be able to switch to the next router (am trying to create a redundancy to by some time in a ddos attack)

the topology i want to build is attached to this, please your help will be highly welcomed.

here is the code i have been able to write for the topology



 

gist extra

unread,
Nov 21, 2016, 2:50:18 PM11/21/16
to ns-3-users
Hello sir, thanks alot for you elaborate reply, i would love to ask , what are your suggestions or possible solution to this.  thank you once more

Tommaso Pecorella

unread,
Nov 21, 2016, 3:13:30 PM11/21/16
to ns-3-users
Hi,

I'd suggest to study the various load balancing and failover techniques on Internet (there's a quite huge literature).
The point you could want to think to is that if you don't want to have a network reconfiguration, you'll need to have a primary/backup or a multi-primary setup, possibly orchestrated by a heartbeat protocol between the two routers.

Now, for most services the switch to a different server is (almost) simple, but for the default router in a host it's not the case - there's just ONE default router, sadly.
If (if) you assume that the hosts are configured through DHCP you could think to a forceful update (check the DHCP protocol).

Another alternative is to make the routers completely identical (MAC addresses, IP addresses, etc.) and to replace the switches with appropriate hash-based splitters...

Summarizing, check the literature. There are plenty of different (and equally good) options.

T.
Reply all
Reply to author
Forward
0 new messages