I have created two containers one left and one right. I had a code given to me and was asked to attached left to one of csma nodes and right to one of the server nodes. So below I attached the left tap to one of the csma nodes.
NetDeviceContainer csmaDevices;
csmaDevices = csma.Install (csmaNodes);
// Use the TapBridgeHelper to connect to the pre-configured tap devices for
// the left side. We go with "UseBridge" mode since the CSMA devices support
// promiscuous mode and can therefore make it appear that the bridge is
// extended into ns-3. The install method essentially bridges the specified
// tap to the specified CSMA device.
TapBridgeHelper tapBridge;
tapBridge.SetAttribute ("Mode", StringValue ("UseBridge"));
tapBridge.SetAttribute ("DeviceName", StringValue ("tap-left"));
tapBridge.Install (csmaNodes.Get (0), csmaDevices.Get (0));
I had no issue attaching left to one of the csmaNodes(Client).
My issue is on the server side.
// set remote Servers
TimeValue val (Time("0ms"));
std::vector<
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
// v3: learner contacts multiple DERs sending messages of different size....
// Default Network topology, 9 nodes in a star
/*
n2 n3 n4
\ | /
\|/
n1---n0---n5
/| \
/ | \
n8 n7 n6
*/
// Default Network Topology
// n6 n7 n8
// \ | /
// \|/
// 10.1.150.0
// n5--- n0 -------------- n1 n2 n3 n4
// point-to-point | | | |
// ================
// LAN 10.1.200.0
// - CBR Traffic goes from the star "arms" to the "hub"
// - Tracing of queues and packet receptions to file
// "tcp-star-server.tr"
// - pcap traces also generated in the following files
// "tcp-star-server-$n-$i.pcap" where n and i represent node and interface
// numbers respectively
// Usage examples for things you might want to tweak:
// ./waf --run="tcp-star-server"
// ./waf --run="tcp-star-server --nNodes=25"
// ./waf --run="tcp-star-server --nNodes=25 --mNodes=12"
// ./waf --run="tcp-star-server --ns3::LRApplication::DataRate=10000"
//
// See the ns-3 tutorial for more info on the command line:
// http://www.nsnam.org/tutorials.html
#include
#include
#include
#include
#include
#include
#include
#include
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/applications-module.h"
#include "ns3/ipv4-global-routing-helper.h"
#include "ns3/csma-module.h"
#include "ns3/flow-monitor-helper.h"
#include "ns3/flow-monitor-module.h"
#include "ns3/stats-module.h"
#include "ns3/netanim-module.h"
//#include "ns3/random-variable.h"
#include "ns3/tap-bridge-module.h"
#include // std::sort
#include
// WiFi Start
#include
#include "ns3/mobility-module.h"
#include "ns3/wifi-module.h"
//#include "wifi-example-apps.h"
// WiFi End
using namespace ns3;
//using namespace std;
NS_LOG_COMPONENT_DEFINE ("DashSimulation");
// LR Trace Start
int64_t l_packetDrops = 0;
uint64_t l_packetDropBytes = 0;
// flow monitor
FlowMonitorHelper flowmon_helper;
Ptr monitor;
std::ofstream netStatsOut; // Create an output file stream (optional)
std::ofstream netHist; // Create an output file stream (optional)
/*
class NS3ElectricalModel {
public:
void Throughput ();
private:
};
*/
void LejlaThroughput () // in Mbps calculated every 0.5s
{
Ptr classifier=DynamicCast(flowmon_helper.GetClassifier());
std::string proto;
std::map< FlowId, FlowMonitor::FlowStats > stats = monitor->GetFlowStats();
netStatsOut << " Time: " << Simulator::Now ().GetSeconds () << std::endl;
for (std::map< FlowId, FlowMonitor::FlowStats>::iterator
flow=stats.begin(); flow!=stats.end(); flow++)
{
Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow(flow->first);
switch(t.protocol)
{
case(6):
proto = "TCP";
break;
case(17):
proto = "UDP";
break;
default:
exit(1);
}
netStatsOut << "FlowID: " << flow->first << " (" << proto << " "
<< t.sourceAddress << " / " << t.sourcePort << " --> "
<< t.destinationAddress << " / " << t.destinationPort << ")" << std::endl;
// printStats(flow->second);
netStatsOut << " Tx Bytes: " << flow->second.txBytes << std::endl;
netStatsOut << " Rx Bytes: " << flow->second.rxBytes << std::endl;
netStatsOut << " Tx Packets: " << flow->second.txPackets << std::endl;
netStatsOut << " Rx Packets: " << flow->second.rxPackets << std::endl;
netStatsOut << " Lost Packets: " << flow->second.lostPackets << std::endl;
netStatsOut << " Pkt Lost Ratio: " << ((double)flow->second.txPackets-(double)flow->second.rxPackets)/(double)flow->second.txPackets << std::endl;
netStatsOut << " Throughput: " << (( ((double)flow->second.rxBytes*8)/(1000000) ) / .5) << std::endl;
netStatsOut << " Mean{Delay}: " << (flow->second.delaySum.GetSeconds()/flow->second.rxPackets) << std::endl;
netStatsOut << " Mean{Jitter}: " << (flow->second.jitterSum.GetSeconds()/(flow->second.rxPackets)) << std::endl;
}
Simulator::Schedule (Seconds (.5), &LejlaThroughput); // Callback every 0.5s
}
void
printStats (FlowMonitor::FlowStats st) {
netHist << "Lost: " << st.lostPackets ;
netHist << " Rx: " << st.rxPackets << " Size: " << st.rxBytes;
if (st.rxPackets > 0)
{
//netHist << " " <<(st.jitterSum.GetSeconds() / (st.rxPackets-1)) ;
netHist << " Hop: " << st.timesForwarded / st.rxPackets + 1;
Time duration = (st.timeLastRxPacket - st.timeFirstRxPacket );
netHist << " T: "
<< duration.GetSeconds ();
// netHist << " Throughput: " << (( ((double)st.rxBytes*8)/(1000000) ) / .5) << std::endl;
netHist << " TP: " << (( ((double)st.rxBytes*8)/(1000) ) / (duration.GetSeconds ())) << std::endl;
}
for (uint32_t i=0; i 0)
{
netHist << " Mean{Delay}: "
<< (st.delaySum.GetSeconds() / st.rxPackets) << std::endl;
netHist << " Mean{Jitter}: "
<< (st.jitterSum.GetSeconds() / (st.rxPackets-1)) << std::endl;
netHist << " Mean{Hop Count}: "
<< st.timesForwarded / st.rxPackets + 1 << std::endl;
Time duration = (st.timeLastRxPacket - st.timeFirstRxPacket );
netHist << " Time: "
<< duration.GetSeconds () << std::endl;
// netHist << " Throughput: " << (( ((double)st.rxBytes*8)/(1000000) ) / .5) << std::endl;
netHist << " Throughput: " << (( ((double)st.rxBytes*8)/(1000) ) / (duration.GetSeconds ())) << std::endl;
}
// if (false)
{
netHist << "***********Delay Histogram" << std::endl;
for (uint32_t i=0; i derAdjacencyList (N);
// std::vector learnerAdjacencyList (M);
for(uint32_t i=0; iGetDevice(0)->GetMtu() << std::endl;
NS_LOG_INFO("MTU P2P " << p2pNodes.Get(0)->GetDevice(0)->GetMtu());
//set local network
CsmaHelper csma;
csma.SetChannelAttribute ("DataRate", StringValue ("100Mbps"));
csma.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (6560)));
NetDeviceContainer csmaDevices;
csmaDevices = csma.Install (csmaNodes);
// Use the TapBridgeHelper to connect to the pre-configured tap devices for
// the left side. We go with "UseBridge" mode since the CSMA devices support
// promiscuous mode and can therefore make it appear that the bridge is
// extended into ns-3. The install method essentially bridges the specified
// tap to the specified CSMA device.
TapBridgeHelper tapBridge;
tapBridge.SetAttribute ("Mode", StringValue ("UseBridge"));
tapBridge.SetAttribute ("DeviceName", StringValue ("tap-left"));
tapBridge.Install (csmaNodes.Get (0), csmaDevices.Get (0));
// set remote Servers
TimeValue val (Time("0ms"));
std::vector derDeviceAdjacencyList (N);
for(uint32_t i=0; iGetDevice(0)->GetMtu() << std::endl;
}
tapBridge.SetAttribute ("DeviceName", StringValue ("tap-right"));
tapBridge.Install (derNodes.Get (1), derDeviceAdjacencyList[1].Get(1));
// Install network stacks on the nodes
InternetStackHelper internet;
internet.Install (derNodes); // proxy node part of this
internet.Install (p2pNodes.Get (0));
internet.Install (csmaNodes);
// add IP addresses.
NS_LOG_INFO ("Assign IP Addresses.");
Ipv4AddressHelper ipv4;
std::vector derInterfaceAdjacencyList (N);
for(uint32_t i=0; i