Wanted: OpenFlow switch examples with multiple switches/nodes

2,567 views
Skip to first unread message

Syd

unread,
Jun 23, 2011, 8:11:41 PM6/23/11
to ns-3-users
Hi Everyone,
Do you guys have any simple examples of an OpenFlow
network with at least 2 switches and multiple nodes (i.e. nodes which
are directly and indirectly connected to the switches)? It appears
that OpenFlow will only work with CSMA type networks (as opposed to
point to point) and so, I have attempted to expand the example which
comes with the NS3 package. However, I am unable to send packets
between any nodes (PS. I receive no errors/log messages though).
Below is a simple example. If you guys can comment as to why its not
working, I would totally appreciate this.

Cheers!
Syd



// Network topology
// Two switches controlled by 2 controllers.
// n0 connects to OFSw1 and n1 connects to OFSw2 via csma channel.
// n1 connects to n2 via p2p channel
//
//
// csma csma csma csma
// n0 ------- OFSw0 -------- OFSw1 ---------- n1 ------ n2
// Contr0 Contr1
//
// - If order of adding nodes and netdevices is kept:
// n0 = 00:00:00;00:00:01, n1 = 00:00:00:00:00:03, n3 =
00:00:00:00:00:07
// and port number corresponds to node number, so port 0 is connected
to n0, for example.

#include <iostream>
#include <fstream>
#include <string>
#include <cassert>


#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "ns3/applications-module.h"
#include "ns3/openflow-module.h"
#include "ns3/log.h"
#include "ns3/point-to-point-module.h"
#include "ns3/csma-module.h"

using namespace ns3;
using namespace std;

NS_LOG_COMPONENT_DEFINE ("OpenFlowUDP");

void SendStuff (Ptr<Socket> sock, Ipv4Address dstaddr, uint16_t port);
void BindSock (Ptr<Socket> sock, Ptr<NetDevice> netdev);
void srcSocketRecv (Ptr<Socket> socket);
void dstSocketRecv (Ptr<Socket> socket);
void node_fail();


bool verbose = false;
bool use_drop = false;
ns3::Time timeout = ns3::Seconds (30);

bool
SetVerbose (std::string value)
{
verbose = true;
return true;
}

int
main (int argc, char *argv[])
{
CommandLine cmd;
cmd.AddValue ("v", "Verbose (turns on logging).", MakeCallback
(&SetVerbose));
cmd.AddValue ("verbose", "Verbose (turns on logging).", MakeCallback
(&SetVerbose));

cmd.Parse (argc, argv);

if (verbose)
{
LogComponentEnable ("OpenFlowUDP", LOG_LEVEL_INFO);
LogComponentEnable ("OpenFlowInterface", LOG_LEVEL_INFO);
LogComponentEnable ("OpenFlowSwitchNetDevice", LOG_LEVEL_INFO);
}

NS_LOG_INFO ("Create nodes.");
NodeContainer csmaNodes;
csmaNodes.Create (3);

NodeContainer OFSwitch;
OFSwitch.Create (2);

NS_LOG_INFO ("Build Topology");
CsmaHelper csma;
csma.SetChannelAttribute ("DataRate", DataRateValue (5000000));
csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));

NetDeviceContainer csmaNetDevices, link;
NetDeviceContainer switchDevices0, switchDevices1;

// connect node0 to OFSw0
link = csma.Install (NodeContainer (csmaNodes.Get (0),
OFSwitch.Get(0)));
csmaNetDevices.Add (link.Get (0));
switchDevices0.Add (link.Get (1));

// connect node1 to OFSw1
link = csma.Install (NodeContainer (csmaNodes.Get (1),
OFSwitch.Get(1)));
csmaNetDevices.Add (link.Get (0));
switchDevices1.Add (link.Get (1));

// connect node1 to node2
link = csma.Install (NodeContainer (csmaNodes.Get (1),
csmaNodes.Get(2)));
csmaNetDevices.Add (link.Get (0));
csmaNetDevices.Add (link.Get (1));

// connect OFSw0 to OFSw1
link = csma.Install (NodeContainer (OFSwitch.Get (0),
OFSwitch.Get(1)));
switchDevices0.Add (link.Get (0));
switchDevices1.Add (link.Get (1));

Ipv4GlobalRoutingHelper::PopulateRoutingTables ();

// Create the switch netdevice, which will do the packet switching
Ptr<Node> OFNode0 = OFSwitch.Get (0);
Ptr<Node> OFNode1 = OFSwitch.Get (1);
OpenFlowSwitchHelper OFSwHelper;

// Install controller0 for OFSw0
Ptr<ns3::ofi::LearningController> controller0 =
CreateObject<ns3::ofi::LearningController> ();
if (!timeout.IsZero ()) controller0->SetAttribute ("ExpirationTime",
TimeValue (timeout));
OFSwHelper.Install (OFNode0, switchDevices0, controller0);

// Install controller1 for OFSw1
Ptr<ns3::ofi::LearningController> controller1 =
CreateObject<ns3::ofi::LearningController> ();
if (!timeout.IsZero ()) controller1->SetAttribute ("ExpirationTime",
TimeValue (timeout));
OFSwHelper.Install (OFNode1, switchDevices1, controller1);

// Add internet stack to the terminals
InternetStackHelper internet;
internet.Install (csmaNodes);

Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.0");
address.Assign (csmaNetDevices);

// print IP address of nodes
for (int i=0; i<3; i++)
{
Ptr<Node> n = csmaNodes.Get (i);
Ptr<Ipv4> ipv4 = n->GetObject<Ipv4> ();
Ipv4InterfaceAddress ipv4_int_addr = ipv4->GetAddress (1, 0);
Ipv4Address ip_addr = ipv4_int_addr.GetLocal ();
NS_LOG_INFO ("Node: " << i << " IP Address: "<< ip_addr);
}


// create socket to destination node
Ptr<Socket> dstSocket = Socket::CreateSocket (csmaNodes.Get(0),
UdpSocketFactory::GetTypeId());
uint16_t dstPort = 9;
Ipv4Address dstAddr ("10.1.1.1");
InetSocketAddress dstLocalAddr (Ipv4Address::GetAny (), dstPort);
dstSocket->Bind(dstLocalAddr);
dstSocket->SetRecvCallback (MakeCallback (&dstSocketRecv));

// create socket from source node
Ptr<Socket> srcSocket[1];
srcSocket[0] = Socket::CreateSocket (csmaNodes.Get(1),
UdpSocketFactory::GetTypeId());
srcSocket[0]->Bind ();
srcSocket[0]->SetRecvCallback (MakeCallback (&srcSocketRecv));

LogComponentEnableAll (LOG_PREFIX_TIME);

Simulator::Schedule (Seconds (1),&SendStuff, srcSocket[0], dstAddr,
dstPort);

Simulator::Run ();
Simulator::Destroy ();

return 0;
}

void node_fail()
{
//sw2.SetDown (2);
;
}

// send packet from source
void SendStuff(Ptr<Socket> sock, Ipv4Address dstaddr, uint16_t port)
{
NS_LOG_INFO ("In SendStuff");
Ptr<Packet> p = Create<Packet> (reinterpret_cast<const uint8_t*>
("hello"),5);// Send hello msg to dst
p->AddPaddingAtEnd (1);
sock->SendTo (p, 0, InetSocketAddress (dstaddr,port));
return;
}

void BindSock(Ptr<Socket> sock, Ptr<NetDevice> netdev)
{
sock->BindToNetDevice (netdev);
return;
}

// receive packet from destination
void srcSocketRecv (Ptr<Socket> socket)
{
Address from;
Ptr<Packet> packet = socket->RecvFrom (from);
packet->RemoveAllPacketTags ();
packet->RemoveAllByteTags ();
InetSocketAddress address = InetSocketAddress::ConvertFrom (from);
NS_LOG_INFO ("Source Received " << packet->GetSize () << " bytes
from " << address.GetIpv4());
}

// receive packet from source and send reply packet to destination
void dstSocketRecv (Ptr<Socket> socket)
{
Address from;
Ptr<Packet> packet = socket->RecvFrom (from);
packet->RemoveAllPacketTags ();
packet->RemoveAllByteTags ();
uint8_t buf[packet->GetSize()]; // Create storage for pkt data
packet->CopyData (buf, packet->GetSize()); // Dump pkt data in buf
InetSocketAddress ipAddress = InetSocketAddress::ConvertFrom (from);
NS_LOG_INFO ("Destination Received signal " <<buf << " from " <<
ipAddress.GetIpv4 ());
NS_LOG_INFO ("Triggering packet back to source node's interface 1");

double alpha(1.0);
string alpha_str;
ostringstream ostr;
ostr << alpha;

alpha_str=ostr.str();
char *buf_alpha;
buf_alpha=&alpha_str[0];
Ipv4Address dest= ipAddress.GetIpv4();
Ptr<Packet> pSrc = Create<Packet> (reinterpret_cast<const
uint8_t*>(buf_alpha),12);
pSrc->AddPaddingAtEnd (1);
socket->SendTo (pSrc, 0, InetSocketAddress
(dest,ipAddress.GetPort() ));

}



John Abraham

unread,
Jun 24, 2011, 10:23:11 AM6/24/11
to ns-3-users
you might want to try adding

srcSocket[0]->BindToNetDevice (csmaNetDevices.Get(1));

-john

Ali Sydney

unread,
Jun 24, 2011, 12:16:14 PM6/24/11
to ns-3-...@googlegroups.com
Great! and now I am able to send pkts between n1 and n0. With this same intuition, I attempted to send pkts from n2 to n0 but was unsuccessful (no error were produced). My source socket looks as follows:

srcSocket[0] = Socket::CreateSocket (csmaNodes.Get(2), UdpSocketFactory::GetTypeId());
srcSocket[0]->BindToNetDevice (csmaNetDevices.Get(3));

Furthermore, if I reverse the sockets and now try to send pkts from n0 to n2, n0 sends the pkt but it never arrives at n2. In fact, it appears that a pkt from n0 gets flooded by the first OpenFlow switch (OFSw0), and also by the second OpenFlow switch (OFSw1), but does not make it to n2. I suspect that the routing tables have not been populated on any of the nodes. However, with the OpenFlow switch, I populate routing tables before creating the OpenFlow switches and perhaps this may be an issue. 

Below is the reverse socket config:

  Ptr<Socket> dstSocket = Socket::CreateSocket (csmaNodes.Get(2),        UdpSocketFactory::GetTypeId());
  uint16_t dstPort = 9;
  Ipv4Address dstAddr ("10.1.1.4");
  InetSocketAddress dstLocalAddr (Ipv4Address::GetAny (), dstPort);
  dstSocket->Bind(dstLocalAddr);
  dstSocket->SetRecvCallback (MakeCallback (&dstSocketRecv));

  Ptr<Socket> srcSocket[1];
  srcSocket[0] = Socket::CreateSocket (csmaNodes.Get(0), UdpSocketFactory::GetTypeId());
  srcSocket[0]->BindToNetDevice (csmaNetDevices.Get(0));
  srcSocket[0]->SetRecvCallback (MakeCallback (&srcSocketRecv));


Any help is greatly appreciated!
-Syd



--
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To post to this group, send email to ns-3-...@googlegroups.com.
To unsubscribe from this group, send email to ns-3-users+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ns-3-users?hl=en.


John Abraham

unread,
Jun 24, 2011, 12:35:28 PM6/24/11
to ns-3-users
not really following the second set of changes.
Besides, under such circumstances,I would
1. EnableAscii traces
2. Enablepcaps
3. Print Routing tables.
-john
> ...
>
> read more »

Ali Sydney

unread,
Jun 28, 2011, 4:44:30 PM6/28/11
to ns-3-...@googlegroups.com
Hi Everyone,
                  I am still having some ARP issues with this OpenFlow network. Any help is appreciated.


Below is the network:

    csma            csma             csma        csma

n0 ------- OFSw0 -------- OFSw1 ----------  n1 ------ n2

Goal 
1. n2 sends UDP packet to n0.
2. n0 sends UDP reply to n2

Actual Communication (from traceroute)
1. n2 sends ARP pkt to n1
2. n1 sends reply ARP to n2
3. n2 sends UDP pkt to n1
4. n1 sends ARP to n0 (through OFSw1 & 0)
5. n0 sends reply ARP to n1 (through OFSw0 & 1)
6. n1 sends UDP pkt to n0 (through OFSw1 & 0)
7. n0 does not send an ARP or UDP pkt to n1

No errors occur.

NB. If I remove OFSw0 and OFSw1, n2 can communicate successfully with n0. 

I do apologize for pasting all this code in here, but I would like to show precisely what I'm doing so that you guys won't get confused and provide feedback accordingly.

The Code
________________________________________________________


#include <iostream>
#include <fstream>
#include <string>
#include <cassert>


#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "ns3/applications-module.h"
#include "ns3/openflow-module.h"
#include "ns3/log.h"
#include "ns3/point-to-point-module.h"
#include "ns3/csma-module.h"

using namespace ns3;
using namespace std;

NS_LOG_COMPONENT_DEFINE ("OpenFlowUDP");

// Function definitions to send a receive packets
void SendStuff (Ptr<Socket> sock, Ipv4Address dstaddr, uint16_t port);
void BindSock (Ptr<Socket> sock, Ptr<NetDevice> netdev);
void srcSocketRecv (Ptr<Socket> socket);
void dstSocketRecv (Ptr<Socket> socket);


bool verbose = false;
bool use_drop = false;

ns3::Time timeout = ns3::Seconds (30);

bool
SetVerbose (std::string value)
{
  verbose = true;
  return true;
}

int
main (int argc, char *argv[])
{
  CommandLine cmd;
  cmd.AddValue ("v", "Verbose (turns on logging).", MakeCallback (&SetVerbose));
  cmd.AddValue ("verbose", "Verbose (turns on logging).", MakeCallback (&SetVerbose));

  cmd.Parse (argc, argv);

  if (verbose)
    {
      LogComponentEnable ("OpenFlowUDP", LOG_LEVEL_INFO);
      LogComponentEnable ("OpenFlowInterface", LOG_LEVEL_INFO);
      LogComponentEnable ("OpenFlowSwitchNetDevice", LOG_LEVEL_INFO);
    }

  NS_LOG_INFO ("Create nodes.");
  NodeContainer csmaNodes;
  csmaNodes.Create (3);

  // Create OpenFlow switches
  NodeContainer OFSwitch;
  OFSwitch.Create (2);

  NS_LOG_INFO ("Build Topology");
  CsmaHelper csma;
  csma.SetChannelAttribute ("DataRate", DataRateValue (5000000));
  csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));

  NetDeviceContainer csmaNetDevices0, csmaNetDevices1, link;
  NetDeviceContainer switchDevices0, switchDevices1;

  // Connect n0 to OFSw0
  link = csma.Install (NodeContainer (csmaNodes.Get (0), OFSwitch.Get(0)));
  csmaNetDevices0.Add (link.Get (0));
  switchDevices0.Add (link.Get (1));

  // Connect n1 to OFSw1
  link = csma.Install (NodeContainer (csmaNodes.Get (1), OFSwitch.Get(1)));
  csmaNetDevices0.Add (link.Get (0));
  switchDevices1.Add (link.Get (1));

   // Connect n1 to n2
  link = csma.Install (NodeContainer (csmaNodes.Get (1), csmaNodes.Get(2)));
  csmaNetDevices1.Add (link.Get (0));
  csmaNetDevices1.Add (link.Get (1));

  // Connect OFSw0 to OFSw1
  link = csma.Install (NodeContainer (OFSwitch.Get (0), OFSwitch.Get(1)));
  switchDevices0.Add (link.Get (0));
  switchDevices1.Add (link.Get (1));

  // Add internet stack to the terminals
 InternetStackHelper internet;

Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.0");
address.Assign (csmaNetDevices0);

 address.SetBase ("10.1.2.0", "255.255.255.0");
 address.Assign (csmaNetDevices1);

  Ipv4GlobalRoutingHelper::PopulateRoutingTables ();

    // Create the switch netdevice, which will do the packet switching
  Ptr<Node> OFNode0 = OFSwitch.Get (0);
  Ptr<Node> OFNode1 = OFSwitch.Get (1);
  OpenFlowSwitchHelper OFSwHelper;

  // Install controller0 for OFSw0
  Ptr<ns3::ofi::LearningController> controller0 = CreateObject<ns3::ofi::LearningController> ();
  if (!timeout.IsZero ()) controller0->SetAttribute ("ExpirationTime", TimeValue (timeout));
  OFSwHelper.Install (OFNode0, switchDevices0, controller0);

 // Install controller1 for OFSw1
  Ptr<ns3::ofi::LearningController> controller1 = CreateObject<ns3::ofi::LearningController> ();
 if (!timeout.IsZero ()) controller1->SetAttribute ("ExpirationTime", TimeValue (timeout));
 OFSwHelper.Install (OFNode1, switchDevices1, controller1);

  // Create destination socket
  Ptr<Socket> dstSocket = Socket::CreateSocket (csmaNodes.Get(0), UdpSocketFactory::GetTypeId());
  uint16_t dstPort = 9;
  Ipv4Address dstAddr ("10.1.1.1");
  InetSocketAddress dstLocalAddr (Ipv4Address::GetAny (), dstPort);
  dstSocket->Bind(dstLocalAddr);
  //dstSocket->BindToNetDevice (csmaNetDevices0.Get(0));
  dstSocket->SetRecvCallback (MakeCallback (&dstSocketRecv));
 
 // Create source socket
  Ptr<Socket> srcSocket[1];
  srcSocket[0] = Socket::CreateSocket (csmaNodes.Get(2), UdpSocketFactory::GetTypeId());
  srcSocket[0]->BindToNetDevice (csmaNetDevices1.Get(1));
  srcSocket[0]->SetRecvCallback (MakeCallback (&srcSocketRecv));

  LogComponentEnableAll (LOG_PREFIX_TIME);

  csma.EnablePcapAll ("openflow-switch", false);
  AsciiTraceHelper ascii;
  csma.EnableAsciiAll (ascii.CreateFileStream ("openflow.tr"));

 // Schedule a pkt transmission at 1s
 Simulator::Schedule (Seconds (1),&SendStuff, srcSocket[0], dstAddr, dstPort);

  // Trace routing tables   ** Not working** 
 // Ipv4GlobalRoutingHelper g;
 // Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper> ("openflow.routes", std::ios::out);
 // g.PrintRoutingTableAllAt (Seconds (1), routingStream);

  Simulator::Run ();
  Simulator::Destroy ();

  return 0;
}

// Function to send pkt from source to destination
void SendStuff(Ptr<Socket> sock, Ipv4Address dstaddr, uint16_t port)
{
  NS_LOG_INFO ("******** In SendStuff");
  Ptr<Packet> p = Create<Packet> (reinterpret_cast<const uint8_t*> ("hello"),5);// Send hello msg to dst
  p->AddPaddingAtEnd (1);
  sock->SendTo (p, 0, InetSocketAddress (dstaddr,port));
  return;
}

void BindSock(Ptr<Socket> sock, Ptr<NetDevice> netdev)
{
  sock->BindToNetDevice (netdev);
  return;
}

// Function to receive packet from destination
void srcSocketRecv (Ptr<Socket> socket)
{
  NS_LOG_INFO ("***** In srcSocketRecv");
  Address from;
  Ptr<Packet> packet = socket->RecvFrom (from);
  packet->RemoveAllPacketTags ();
InetSocketAddress address = InetSocketAddress::ConvertFrom (from);
  NS_LOG_INFO ("Source Received " << packet->GetSize () << " bytes from " << address.GetIpv4());
}

// Function to receive packet from source and send reply back to source
void dstSocketRecv (Ptr<Socket> socket)
{
  NS_LOG_INFO ("***** In dstSocketRecv");
  Address from;
  Ptr<Packet> packet = socket->RecvFrom (from);
  packet->RemoveAllPacketTags ();
  packet->RemoveAllByteTags ();
  uint8_t buf[packet->GetSize()]; // Create storage for pkt data
  packet->CopyData (buf, packet->GetSize()); // Dump pkt data in buf
  InetSocketAddress ipAddress = InetSocketAddress::ConvertFrom (from);
  NS_LOG_INFO ("Destination Received signal " <<buf << " from " << ipAddress.GetIpv4 ());
  NS_LOG_INFO ("Triggering packet back to source node's interface 1");

  double alpha(1.0);
  string alpha_str;
  ostringstream ostr;
  ostr << alpha;

  alpha_str=ostr.str();
  char *buf_alpha;
  buf_alpha=&alpha_str[0];
  Ipv4Address dest= ipAddress.GetIpv4();
  Ptr<Packet> pSrc = Create<Packet> (reinterpret_cast<const uint8_t*>(buf_alpha),12);
  pSrc->AddPaddingAtEnd (1);
  socket->SendTo (pSrc, 0, InetSocketAddress (dest,ipAddress.GetPort() ));

}


_______________________________________________





--

John Abraham

unread,
Jun 29, 2011, 11:33:09 AM6/29/11
to ns-3-users
have you tried printing the Routing Table with something like
Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper>
("openflow.routes", std::ios::out);
//g.PrintRoutingTableAllAt (Seconds (1), routingStream);
for (uint32_t i = 0 ; i <csmaNodes.GetN ();i++)
{
Ptr <Node> n = csmaNodes.Get (i);
Ptr <Ipv4> ipv4 = n->GetObject <Ipv4> ();
ipv4->GetRoutingProtocol ()->PrintRoutingTable (routingStream);
> > > > > Hi...
>
> read more »

Ali Sydney

unread,
Jun 29, 2011, 11:47:21 AM6/29/11
to ns-3-...@googlegroups.com
I've tried the following to print the tables at every second but that produces some errors:

  Ipv4GlobalRoutingHelper g;
  Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper> ("openflow.routes", std::ios::out);
  g.PrintRoutingTableAllAt (Seconds (1), routingStream);

However, your version produces the routing tables at time 0 (or the initial routing tables).

Now, for the following diagram, I sent a packet successfully between n1 and n0, and made a note of the routing tables.
I then sent a packet from n2 to n0, and the routing tables are identical, but n0 refuses to send the reply UDP packet. And this is strange, because n0 firsts sends an ARP reply packet back to n1, but when n1 finally sends the UDP packet to n0, n0 does not even bother to create a reply UDP packet.

   csma            csma             csma        csma
n0 ------- OFSw0 -------- OFSw1 ----------  n1 ------ n2

Thanks,
Syd

>
> read more »

John Abraham

unread,
Jun 29, 2011, 11:29:50 AM6/29/11
to ns-3-users
Please try something like this, while printing the RoutingTable

Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper>
("openflow.routes",std::ios::out);
for (uint32_t i = 0 ; i <csmaNodes.GetN ();i++)
{
Ptr <Node> n = csmaNodes.Get (i);
Ptr <Ipv4> ipv4 = n->GetObject <Ipv4> ();
ipv4->GetRoutingProtocol ()->PrintRoutingTable (routingStream);
}

and see if the table has appropriate entries.
-john
> > > > > Hi...
>
> read more »

John Abraham

unread,
Jun 29, 2011, 12:22:04 PM6/29/11
to ns-3-users
oops previous message got resent. in any case,
does priting the routing table when the packet is received reveal
anything suspicious?

Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper>
("openflow.routes2", std::ios::out);
Ptr <Node> n = socket->GetNode ();
Ptr <Ipv4> ipv4 = n->GetObject <Ipv4> ();
ipv4->GetRoutingProtocol ()->PrintRoutingTable (routingStream);


> > > > n2,...
>
> read more »

John Abraham

unread,
Jun 29, 2011, 12:25:55 PM6/29/11
to ns-3-users
also please apply export NS_LOG=OpenFlowUDP:UdpSocketImpl
to confirm if the routes are bad.
> > >   socket->SendTo (pSrc, 0, InetSocketAddress...
>
> read more »

Ali Sydney

unread,
Jun 29, 2011, 2:54:43 PM6/29/11
to ns-3-...@googlegroups.com
THANKS A MILLION!!!

You were right! When I did "export NS_LOG=OpenFlowUDP:UdpSocketImpl", it appears that there was no route to the destination at the point when n0 received the UDP packet. I'm not to sure why this happened as the routing table looked perfect before packets were transmitted. In any case, inserting the static route did solve the problem!

Thank you!
Syd

On Wed, Jun 29, 2011 at 1:08 PM, John Abraham <john...@gmail.com> wrote:
I believe Global Routing may not work in this case due to the other
end being 2 switches (Don't know the true reason). But try adding the
below static route after populating the global routing table.

 Ptr <Node> n0 = csmaNodes.Get(0);
 Ptr <Ipv4> ipv4 = n0->GetObject <Ipv4> ();
 Ipv4StaticRoutingHelper ipv4RoutingHelper;
 Ptr<Ipv4StaticRouting> staticRouting =
ipv4RoutingHelper.GetStaticRouting (ipv4);
 staticRouting->AddHostRouteTo (Ipv4Address ("10.1.2.2"), Ipv4Address
("10.1.1.2"), 1);

-john
> > > >   NS_LOG_INFO...

劉耕含

unread,
Sep 20, 2012, 11:38:51 PM9/20/12
to ns-3-...@googlegroups.com
Hi everyone:
    I want to simulate openflow routing on fattree topology. As attachment, I want to observe what's the difference between traditional networks and openflow networks. 
Hence, my goal is:
1. Send Udp/Tcp Packets from one host node to the other (for example:c1 --> c4) 
    Now in my test, I just add a flow for test.
2. Observer the response time in traditional case and openflow case, I also want to output the Openflow flow table

But my problem is,
1. In my simulation, our tracefile and netanimation file doesn't output anything (can compiler normally)
2. how to ouput the routing/flow table?

I want to know why it's not working. Thanks in advanced.

BR,

Gordon

//           _l9__   _l10__    ※in our experiment, {l9,l10} and {l5,l6,l7,l8} are full mesh
//          /     \ /      \          ※this program is modified from Ashok Kumar's example 
//         /       /\       \            in https://groups.google.com/forum/?fromgroups=#!topic/ns-3-users/njclO2klIr0
//        /       /  \       \
//       /       /    \       \
//       l5     l6     l7      l8
//       |\     /|     |\     /|
//       | \   / |     | \   / |
//       |  \ /  |     |  \ /  |
//       |  /\   |     |  /\   |
//       |_/ \_|     |_/  \_|
//       l1    l2      l3    l4
//       |      |       |     |
//       c1     c2      c3    c4

Syd於 2011年6月24日星期五UTC+8上午8時11分41秒寫道:
fattree-OF.cc
Message has been deleted
Message has been deleted

outrosdiasvirao

unread,
Feb 18, 2014, 1:19:13 PM2/18/14
to ns-3-...@googlegroups.com
Hi Syd,

29 minutos (15:11)
Could you post your complete code? (A joke: your hands will not fall if you put your complete code here :-)

I tried with success the following code (note that the topology was modified) but until now I can't figure out how to acquire the throughput.
I tried OnOffHelper without success. Someone could help me with a code that shows the thoughput on this openflow network? Thanks.

---

//Works, but I can't get monitoring (throughput, delay, etc.)
//In the shell (terminal): export NS_LOG=OpenFlowUDP:
UdpSocketImpl

//./waf && ./waf --run "scratch/example_openflow_v7 -v"


// Network topology
// Two switches controlled by 2 controllers.
// n0 connects to OFSw0 and n1 connects to OFSw1 via csma channel.

//
//
//            csma            csma             csma    
//        n0 ------- OFSw0 -------- OFSw1 ----------  n1

//                     Contr0           Contr1
//                                             |
//                                             |
//                                             n2



#include <iostream>
#include <fstream>
#include <string>
#include <cassert>


#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "ns3/applications-module.h"
#include "ns3/openflow-module.h"
#include "ns3/log.h"
#include "ns3/point-to-point-module.h"
#include "ns3/csma-module.h"
#include "ns3/flow-monitor-module.h"


using namespace ns3;
using namespace std;

NS_LOG_COMPONENT_DEFINE ("OpenFlowUDP");

void SendStuff (Ptr<Socket> sock, Ipv4Address dstaddr, uint16_t port);
void BindSock (Ptr<Socket> sock, Ptr<NetDevice> netdev);
void srcSocketRecv (Ptr<Socket> socket);
void dstSocketRecv (Ptr<Socket> socket);
void node_fail();



bool verbose = false;
bool use_drop = false;
ns3::Time timeout = ns3::Seconds (30);

bool SetVerbose (std::string value){
  verbose = true;
  return true;
}

int main (int argc, char *argv[])
{
  CommandLine cmd;
  cmd.AddValue ("v", "Verbose (turns on logging).", MakeCallback(&SetVerbose));
  cmd.AddValue ("verbose", "Verbose (turns on logging).", MakeCallback(&SetVerbose));

  cmd.Parse (argc, argv);

  if (verbose)
    {
      LogComponentEnable ("OpenFlowUDP", LOG_LEVEL_INFO);
      LogComponentEnable ("OpenFlowInterface", LOG_LEVEL_INFO);
      LogComponentEnable ("OpenFlowSwitchNetDevice", LOG_LEVEL_INFO);
    }

  NS_LOG_INFO ("Create nodes.");
  NodeContainer csmaNodes;
  csmaNodes.Create (3);
  NodeContainer OFSwitch;
  OFSwitch.Create (2);

  NS_LOG_INFO ("Build Topology");
  CsmaHelper csma;
  csma.SetChannelAttribute ("DataRate", DataRateValue (5000000));
  csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));

  NetDeviceContainer csmaNetDevices, link;
  NetDeviceContainer switchDevices0, switchDevices1;

 // connect node0 to OFSw0
  link = csma.Install (NodeContainer (csmaNodes.Get (0), OFSwitch.Get(0))); //csma e OFSwitch are node containers (ns-3 example file openflow-switch.cc too)
  csmaNetDevices.Add (link.Get (0));  //csmaNetDevices.Get(0)
  switchDevices0.Add (link.Get (1));

 // connect node1 to OFSw1

  link = csma.Install (NodeContainer (csmaNodes.Get (1), OFSwitch.Get(1)));
  csmaNetDevices.Add (link.Get (0)); //csmaNetDevices.Get(1)
  switchDevices1.Add (link.Get (1));

 // connect node2 toOFSw1
  link = csma.Install (NodeContainer (csmaNodes.Get (2), OFSwitch.Get(1)));
  csmaNetDevices.Add (link.Get (0)); //csmaNetDevices.Get(2)
  switchDevices1.Add (link.Get (1));

 // connect OFSw0 to OFSw1

  link = csma.Install (NodeContainer (OFSwitch.Get (0),OFSwitch.Get(1)));
  switchDevices0.Add (link.Get (0));
  switchDevices1.Add (link.Get (1));

  Ipv4GlobalRoutingHelper::PopulateRoutingTables ();


    // Create the switch netdevice, which will do the packet switching
  Ptr<Node> OFNode0 = OFSwitch.Get (0);
  Ptr<Node> OFNode1 = OFSwitch.Get (1);
  OpenFlowSwitchHelper OFSwHelper;

 // Install controller0 for OFSw0
  Ptr<ns3::ofi::LearningController> controller0 = CreateObject<ns3::ofi::LearningController> ();
  if (!timeout.IsZero ()) controller0->SetAttribute ("ExpirationTime", TimeValue (timeout));
  OFSwHelper.Install (OFNode0, switchDevices0, controller0);

 // Install controller1 for OFSw1
  Ptr<ns3::ofi::LearningController> controller1 = CreateObject<ns3::ofi::LearningController> ();
 if (!timeout.IsZero ()) controller1->SetAttribute ("ExpirationTime", TimeValue (timeout));
 OFSwHelper.Install (OFNode1, switchDevices1, controller1);

   // Add internet stack to the terminals
 InternetStackHelper internet;
 internet.Install (csmaNodes);

 Ipv4AddressHelper address1;
 address1.SetBase ("10.1.1.0", "255.255.255.0");
 //address1.Assign (csmaNetDevices.Get(0));
 address1.Assign (csmaNetDevices);

 /* Ipv4AddressHelper address2;
 address2.SetBase ("10.1.2.0", "255.255.255.0");
 address2.Assign (csmaNetDevices.Get(1));
 
 Ipv4AddressHelper address3;
 address3.SetBase ("10.1.3.0", "255.255.255.0");
 address3.Assign (csmaNetDevices.Get(2));
 */

  /////


// print IP address of nodes
 Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper> ("openflow.routes2", std::ios::out);
 for (int i=0; i<3; i++){

    Ptr<Node> n = csmaNodes.Get (i);
    Ptr<Ipv4> ipv4 = n->GetObject<Ipv4> ();
    Ipv4InterfaceAddress ipv4_int_addr = ipv4->GetAddress (1, 0);
    Ipv4Address ip_addr = ipv4_int_addr.GetLocal (); //Colocou um IP por DHCP

    NS_LOG_INFO ("Node: " << i << " IP Address: "<< ip_addr);
    ipv4->GetRoutingProtocol ()->PrintRoutingTable (routingStream);

  }

 /////
 //Works too, but only add the route when exist a node in a different network
 /* Ptr <Node> n0 = csmaNodes.Get(0);
  Ptr <Ipv4> ipv4_x = n0->GetObject <Ipv4> ();
  Ipv4StaticRoutingHelper ipv4RoutingHelper;
  Ptr<Ipv4StaticRouting> staticRouting =ipv4RoutingHelper.GetStaticRouting (ipv4_x);
  staticRouting->AddHostRouteTo (Ipv4Address ("10.1.1.1"), Ipv4Address("10.2.2.1"), 1);
 */
 /////////////////////////////////////////////////////


 ////////////////////////////////////////////////////////
 //n0 (10.1.1.1) -> n2 (10.1.1.3)

  // create socket to destination node
  Ptr<Socket> dstSocket = Socket::CreateSocket (csmaNodes.Get(0), UdpSocketFactory::GetTypeId());
  uint16_t dstPort = 9;
  Ipv4Address dstAddr ("10.1.1.1");
  InetSocketAddress dstLocalAddr (Ipv4Address::GetAny (), dstPort);
  dstSocket->Bind(dstLocalAddr);
  dstSocket->SetRecvCallback (MakeCallback (&dstSocketRecv));

  // create socket from source node
  Ptr<Socket> srcSocket[1];
  srcSocket[0] = Socket::CreateSocket (csmaNodes.Get(2), UdpSocketFactory::GetTypeId());
  srcSocket[0]->Bind ();

  srcSocket[0]->SetRecvCallback (MakeCallback (&srcSocketRecv));
  srcSocket[0]->BindToNetDevice (csmaNetDevices.Get(2)); //Ligacao dos devices (nodeContainer) da origem e do destino

  /*  /////////////////////////////////////////////////////////////////////
  // Create an OnOff application to send UDP datagrams from n0 to n1.
  NS_LOG_INFO ("Create Applications.");
  uint16_t port = 9;   // Discard port (RFC 863)

  OnOffHelper onoff ("ns3::UdpSocketFactory",
                     Address (InetSocketAddress (Ipv4Address ("10.1.1.1"), port)));  //Node 0 eh o servidor
  onoff.SetConstantRate (DataRate ("500kb/s"));
  ApplicationContainer app = onoff.Install (csmaNodes.Get (1));
  // Start the application
  app.Start (Seconds (1.0));
  app.Stop (Seconds (10.0));
  /////////////////////////////////////////////////////////////////////
  */

  LogComponentEnableAll (LOG_PREFIX_TIME);


  Simulator::Schedule (Seconds (1),&SendStuff, srcSocket[0], dstAddr, dstPort);

  Simulator::Run ();

  ///////////////////////
  //
  // Configure tracing of all enqueue, dequeue, and NetDevice receive events.
  // Trace output will be sent to the file "openflow-switch.tr"
  //
  //AsciiTraceHelper ascii;
  //csma.EnableAsciiAll (ascii.CreateFileStream ("openflow-switch.tr"));

  ///////////////////
  // 8. Install FlowMonitor on all nodes
  FlowMonitorHelper flowmon;
  Ptr<FlowMonitor> monitor = flowmon.InstallAll ();

  // 9. Run simulation for 10 seconds
  Simulator::Stop (Seconds (10));

  //
  // Also configure some tcpdump traces; each interface will be traced.
  // The output files will be named:
  //     openflow-switch-<nodeId>-<interfaceId>.pcap
  // and can be read by the "tcpdump -r" command (use "-tt" option to
  // display timestamps correctly)
  //

  csma.EnablePcapAll ("openflow-switch", false);

  //
  // Now, do the actual simulation.
  //
  NS_LOG_INFO ("Run Simulation.");
  Simulator::Run ();

  // 10. Print per flow statistics
  monitor->CheckForLostPackets ();
  Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier> (flowmon.GetClassifier ());
  std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats ();
  for (std::map<FlowId, FlowMonitor::FlowStats>::const_iterator i = stats.begin (); i != stats.end (); ++i)
    {
      // first 2 FlowIds are for ECHO apps, we don't want to display them
      //
      // Duration for throughput measurement is 9.0 seconds, since
      //   StartTime of the OnOffApplication is at about "second 1"
      // and
      //   Simulator::Stops at "second 10".
      //      if (i->first > 2)
      //  {
          Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow (i->first);
          std::cout << "\nFlow " << i->first << " (" << t.sourceAddress << " -> " << t.destinationAddress << ")\n";
          std::cout << "  Tx Packets: " << i->second.txPackets << "\n";
          std::cout << "  Tx Bytes:   " << i->second.txBytes << "\n";
          std::cout << "  TxOffered:  " << i->second.txBytes * 8.0 / 9.0 / 1000 / 1000  << " Mbps\n";
          std::cout << "  Rx Packets: " << i->second.rxPackets << "\n";
          std::cout << "  Rx Bytes:   " << i->second.rxBytes << "\n";
          std::cout << "  Throughput: " << i->second.rxBytes * 8.0 / 9.0 / 1000 / 1000  << " Mbps\n";
          std::cout << "  DelaySum: " << i->second.delaySum << "\n";
          std::cout << "  JitterSum: " << i->second.jitterSum << "\n";
      //  }
    }
  //////////////////////


  Simulator::Destroy ();

  return 0;
}

void node_fail()
{
  //sw2.SetDown (2);
;
}

// send packet from source
void SendStuff(Ptr<Socket> sock, Ipv4Address dstaddr, uint16_t port)
{
  NS_LOG_INFO ("In SendStuff");

  Ptr<Packet> p = Create<Packet> (reinterpret_cast<const uint8_t*> ("hello"),5);// Send hello msg to dst
  p->AddPaddingAtEnd (1);
  sock->SendTo (p, 0, InetSocketAddress (dstaddr,port));
  return;
}

void BindSock(Ptr<Socket> sock, Ptr<NetDevice> netdev)
{
  sock->BindToNetDevice (netdev);
  return;
}

// receive packet from destination

void srcSocketRecv (Ptr<Socket> socket)
{
  Address from;
  Ptr<Packet> packet = socket->RecvFrom (from);
  packet->RemoveAllPacketTags ();
  packet->RemoveAllByteTags ();
  InetSocketAddress address = InetSocketAddress::ConvertFrom (from);
  NS_LOG_INFO ("Source Received " << packet->GetSize () << " bytes from " << address.GetIpv4());
}

// receive packet from source and send reply packet to destination

void dstSocketRecv (Ptr<Socket> socket)
{

  Address from;
  Ptr<Packet> packet = socket->RecvFrom (from);
  packet->RemoveAllPacketTags ();
  packet->RemoveAllByteTags ();
  uint8_t buf[packet->GetSize()]; // Create storage for pkt data
  packet->CopyData (buf, packet->GetSize()); // Dump pkt data in buf
  InetSocketAddress ipAddress = InetSocketAddress::ConvertFrom (from);
  NS_LOG_INFO ("Destination Received signal " <<buf << " from " << ipAddress.GetIpv4 ());
  NS_LOG_INFO ("Triggering packet back to source node's interface 1");

  double alpha(1.0);
  string alpha_str;
  ostringstream ostr;
  ostr << alpha;

  alpha_str=ostr.str();
  char *buf_alpha;
  buf_alpha=&alpha_str[0];
  Ipv4Address dest= ipAddress.GetIpv4();
  Ptr<Packet> pSrc = Create<Packet> (reinterpret_cast<const uint8_t*>(buf_alpha),12);
  pSrc->AddPaddingAtEnd (1);
  socket->SendTo (pSrc, 0, InetSocketAddress (dest,ipAddress.GetPort() ));

}

---

Konstantinos

unread,
Feb 18, 2014, 1:28:35 PM2/18/14
to ns-3-...@googlegroups.com


On Tuesday, February 18, 2014 6:19:13 PM UTC, outrosdiasvirao wrote:
Hi Syd,

29 minutos (15:11)
Could you post your complete code? (A joke: your hands will not fall if you put your complete code here :-)

I tried with success the following code (note that the topology was modified) but until now I can't figure out how to acquire the throughput.
I tried OnOffHelper without success. Someone could help me with a code that shows the thoughput on this openflow network? Thanks.


The problem with your code in not related to OpenFlow but where you are installing FlowMonitor or tracing.
You are calling Simulator::Run() twice. Just delete the highlighted one.  
Message has been deleted

outrosdiasvirao

unread,
Feb 18, 2014, 1:45:35 PM2/18/14
to ns-3-...@googlegroups.com
THANK YOU very much!!! I removed the first occurrence of Simulator::Run() in the previous code.  Now I need to discover if openflow module in ns-3 has support to simulate nodes in different networks. Example:


   csma            csma             csma    
//        n0 ------- OFSw0 -------- OFSw1 ----------  n1
//                     Contr0           Contr1
//                                    |
//                                    |
//                                    n2

In this topology:
n0: 10.1.1.0/24
n1: 10.2.1.0/24
n2: 10.3.1.0/24

This is possible? Someone could help me? Any help is useful.

Again, I'm trying the following code:

---
 address1.Assign (csmaNetDevices.Get(0));
 //address1.Assign (csmaNetDevices);


 Ipv4AddressHelper address2;
 address2.SetBase ("10.1.2.0", "255.255.255.0");
 address2.Assign (csmaNetDevices.Get(1));
 
 Ipv4AddressHelper address3;
 address3.SetBase ("10.1.3.0", "255.255.255.0");
 address3.Assign (csmaNetDevices.Get(2)); 

  /////////////////////////////////////////////////////////////////////
  // Create an OnOff application to send UDP datagrams from n0 to n1.
  NS_LOG_INFO ("Create Applications.");
  uint16_t port = 9;   // Discard port (RFC 863)

  OnOffHelper onoff ("ns3::UdpSocketFactory",
                     Address (InetSocketAddress (Ipv4Address ("10.1.1.1"), port)));  //Node 0 eh o servidor
  onoff.SetConstantRate (DataRate ("500kb/s"));
  ApplicationContainer app = onoff.Install (csmaNodes.Get (1));
  // Start the application
  app.Start (Seconds (1.0));
  app.Stop (Seconds (10.0));
  /////////////////////////////////////////////////////////////////////

  LogComponentEnableAll (LOG_PREFIX_TIME);

  Simulator::Schedule (Seconds (1),&SendStuff, srcSocket[0], dstAddr, dstPort);

Message has been deleted
Message has been deleted

outrosdiasvirao

unread,
Feb 21, 2014, 7:36:02 AM2/21/14
to ns-3-...@googlegroups.com
Hi,

I get a minimal fat-tree example working with openflow. But:
- I can't to associate different networks to the csma nodes. This is a limitation of the ns-3 openflow module?
- There is a controller for each switch, but how can I associate a single controller for all of them? Any help be useful.

My complete source code:


//Works with flow monitoring
//In terminal: export NS_LOG=OpenFlowUDP:UdpSocketImpl (optional: only for UDP debug)

//./waf && ./waf --run "scratch/fattree_openflow_v13 -v"

// Network topology
// 5 switches controlled by 5 controllers.
// n0 connects to OFSw3 and n1 connects to OFSw4 via csma channel.
//
//
//        OF0
//        |  
//        OF1   OF2
//        |     \/    |
//        |     /\    |                     
//    OF3        OF4
//        |           |  
//        n0        n1
//
  OFSwitch.Create (5);


  NS_LOG_INFO ("Build Topology");
  CsmaHelper csma;
  csma.SetChannelAttribute ("DataRate", DataRateValue (5000000));
  csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));

  NetDeviceContainer csmaNetDevices, link;
  NetDeviceContainer switchDevices0, switchDevices1, switchDevices2, switchDevices3, switchDevices4;

 // connect node0 to OFSw3
  link = csma.Install (NodeContainer (csmaNodes.Get (0), OFSwitch.Get(3))); //csma e OFSwitch are node containers (ns-3 example file openflow-switch.cc too)
  csmaNetDevices.Add (link.Get (0));  //csmaNetDevices.Get(0)
  switchDevices3.Add (link.Get (1));

 // connect node1 to OFSw4
  link = csma.Install (NodeContainer (csmaNodes.Get (1), OFSwitch.Get(4)));
  csmaNetDevices.Add (link.Get (0)); //csmaNetDevices.Get(1)
  switchDevices4.Add (link.Get (1));


 // connect node2 toOFSw1
  link = csma.Install (NodeContainer (csmaNodes.Get (2), OFSwitch.Get(1)));
  csmaNetDevices.Add (link.Get (0)); //csmaNetDevices.Get(2)
  switchDevices1.Add (link.Get (1));

 // connect OFSw0 to OFSw1
  link = csma.Install (NodeContainer (OFSwitch.Get (0),OFSwitch.Get(1)));
  switchDevices0.Add (link.Get (0));
  switchDevices1.Add (link.Get (1));

 // connect OFSw1 to OFSw3
  link = csma.Install (NodeContainer (OFSwitch.Get (1),OFSwitch.Get(3)));
  switchDevices1.Add (link.Get (0));
  switchDevices3.Add (link.Get (1));

 // connect OFSw2 to OFSw3
  link = csma.Install (NodeContainer (OFSwitch.Get (2),OFSwitch.Get(3)));
  switchDevices2.Add (link.Get (0));
  switchDevices3.Add (link.Get (1));

 // connect OFSw4 to OFSw1
  link = csma.Install (NodeContainer (OFSwitch.Get (4),OFSwitch.Get(1)));
  switchDevices4.Add (link.Get (0));
  switchDevices1.Add (link.Get (1));


  Ipv4GlobalRoutingHelper::PopulateRoutingTables ();


    // Create the switch netdevice, which will do the packet switching
  Ptr<Node> OFNode0 = OFSwitch.Get (0);
  Ptr<Node> OFNode1 = OFSwitch.Get (1);
  Ptr<Node> OFNode2 = OFSwitch.Get (2);
  Ptr<Node> OFNode3 = OFSwitch.Get (3);
  Ptr<Node> OFNode4 = OFSwitch.Get (4);
  OpenFlowSwitchHelper OFSwHelper;

  //Importante: tem que ser um controller para cada OFSwitch


 // Install controller0 for OFSw0
  Ptr<ns3::ofi::LearningController> controller0 = CreateObject<ns3::ofi::LearningController> ();
  if (!timeout.IsZero ()) controller0->SetAttribute ("ExpirationTime", TimeValue (timeout));
  OFSwHelper.Install (OFNode0, switchDevices0, controller0);

 // Install controller1 for OFSw1
  Ptr<ns3::ofi::LearningController> controller1 = CreateObject<ns3::ofi::LearningController> ();
 if (!timeout.IsZero ()) controller1->SetAttribute ("ExpirationTime", TimeValue (timeout));
 OFSwHelper.Install (OFNode1, switchDevices1, controller1);

 // Install controller2 for OFSw2
  Ptr<ns3::ofi::LearningController> controller2 = CreateObject<ns3::ofi::LearningController> ();
 if (!timeout.IsZero ()) controller2->SetAttribute ("ExpirationTime", TimeValue (timeout));
 OFSwHelper.Install (OFNode2, switchDevices2, controller2);

 // Install controller3 for OFSw3
  Ptr<ns3::ofi::LearningController> controller3 = CreateObject<ns3::ofi::LearningController> ();
 if (!timeout.IsZero ()) controller3->SetAttribute ("ExpirationTime", TimeValue (timeout));
 OFSwHelper.Install (OFNode3, switchDevices3, controller3);

 // Install controller4 for OFSw4
  Ptr<ns3::ofi::LearningController> controller4 = CreateObject<ns3::ofi::LearningController> ();
 if (!timeout.IsZero ()) controller4->SetAttribute ("ExpirationTime", TimeValue (timeout));
 OFSwHelper.Install (OFNode4, switchDevices4, controller4);




   // Add internet stack to the terminals
 InternetStackHelper internet;
 internet.Install (csmaNodes);

 Ipv4AddressHelper address1;
 address1.SetBase ("10.1.1.0", "255.255.255.0");
 //address1.Assign (csmaNetDevices.Get(0));
 address1.Assign (csmaNetDevices);

 /* Ipv4AddressHelper address2;
 address2.SetBase ("10.1.2.0", "255.255.255.0");
 address2.Assign (csmaNetDevices.Get(1));
 
 Ipv4AddressHelper address3;
 address3.SetBase ("10.1.3.0", "255.255.255.0");
 address3.Assign (csmaNetDevices.Get(2));
 */

  /////

// print IP address of nodes
 Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper> ("openflow.routes", std::ios::out);
                     Address (InetSocketAddress (Ipv4Address ("10.1.1.1"), port)));  //Node 0 is the server

  onoff.SetConstantRate (DataRate ("500kb/s"));
  ApplicationContainer app = onoff.Install (csmaNodes.Get (1)); //Node 1 is the client

  // Start the application
  app.Start (Seconds (1.0));
  app.Stop (Seconds (10.0));
  /////////////////////////////////////////////////////////////////////
 

  LogComponentEnableAll (LOG_PREFIX_TIME);

  Simulator::Schedule (Seconds (1),&SendStuff, srcSocket[0], dstAddr, dstPort);

  //Simulator::Run ();

John Abraham

unread,
Jun 29, 2011, 1:08:35 PM6/29/11
to ns-3-users
I believe Global Routing may not work in this case due to the other
end being 2 switches (Don't know the true reason). But try adding the
below static route after populating the global routing table.

Ptr <Node> n0 = csmaNodes.Get(0);
Ptr <Ipv4> ipv4 = n0->GetObject <Ipv4> ();
Ipv4StaticRoutingHelper ipv4RoutingHelper;
Ptr<Ipv4StaticRouting> staticRouting =
ipv4RoutingHelper.GetStaticRouting (ipv4);
staticRouting->AddHostRouteTo (Ipv4Address ("10.1.2.2"), Ipv4Address
("10.1.1.2"), 1);

-john

> > > >   NS_LOG_INFO...
>
> read more »

Ana Carolina de Oliveira Christófaro

unread,
Oct 21, 2015, 10:10:04 PM10/21/15
to ns-3-users
Hello!
Did you find some way to get connectivity between to different networks using Openflow?

etlea...@gmail.com

unread,
May 7, 2018, 3:38:15 AM5/7/18
to ns-3-users
Excuse me, have you got some progress in the connection OpenFlow networks with p2p? Thanks a lot!

在 2015年10月22日星期四 UTC+8上午10:10:04,Ana Carolina de Oliveira Christófaro写道:
Reply all
Reply to author
Forward
0 new messages