(OK)(OK) houshoul experiment


hsl_experiment.txt

#--------------------------------
# 3 files
#--------------------------------

/root/hsl-win7-ns3-root.sh
/root/hsl_install_6_docker-centos-quagga.sh
/opt/share-vm/fedora23server-share/seem-6-win7-switch-docker.cc

/opt/tools/network_simulators/ns3/ns-allinone-3.25/ns-3.25/scratch/seem-6-win7-switch-docker.cc

/home/hsl/hsl-win7-ns3-user.sh

#--------------------------------
# root
#--------------------------------

# step 1
# executed by root, create br_w_[1~6], tap_w_[1~6]

/root/hsl-win7-ns3-root.sh 6 create
/root/hsl-win7-ns3-root.sh 6 destroy

# step 2
# executed by root, create 6 routers, create br_r_[1~6] , tap_r_ , veth_r_ , deth_
/root/hsl_install_6_docker-centos-quagga.sh create
/root/hsl_install_6_docker-centos-quagga.sh destroy

# start NS3
// [root@localhost ns-3.25]# ./waf --run scratch/seem-6-win7-switch-docker --vis

#--------------------------------
# hsl
#--------------------------------

systemctl start vncserver@:1
vncviewer 10.109.253.80:1

# step 2
cd /home/hsl
./waf-user scratch/seem-6-win7-switch-docker

# step 3
cd /home/hsl
./hsl-win7-ns3-user.sh 6 create
./hsl-win7-ns3-user.sh 6 destroy







#--------------------------------
# routers
#--------------------------------

# docker_1
ip route add 10.0.1.0/24 dev eth0
ip route add 10.0.2.0/24 dev eth0
ip route add 10.0.3.0/24 dev eth1
ip route add 10.0.4.0/24 dev eth1
ip route add 10.1.2.0/24 dev eth1

# docker_2
ip route add 10.0.1.0/24 dev eth0
ip route add 10.0.2.0/24 dev eth0
ip route add 10.0.3.0/24 dev eth1
ip route add 10.0.4.0/24 dev eth1
ip route add 10.1.1.0/24 dev eth0

# docker_3
ip route add 10.0.2.0/24 dev eth0
ip route add 10.0.3.0/24 dev eth0
ip route add 10.0.4.0/24 dev eth0
ip route add 10.1.2.0/24 dev eth0
ip route add 192.168.1.0/24 dev eth0

# docker_4
ip route add 10.0.1.0/24 dev eth0
ip route add 10.0.3.0/24 dev eth0
ip route add 10.0.4.0/24 dev eth0
ip route add 10.1.2.0/24 dev eth0
ip route add 192.168.1.0/24 dev eth0

# docker_5
ip route add 10.0.1.0/24 dev eth0
ip route add 10.0.2.0/24 dev eth0
ip route add 10.0.4.0/24 dev eth0
ip route add 10.1.1.0/24 dev eth0
ip route add 192.168.1.0/24 dev eth0

# docker_6
ip route add 10.0.1.0/24 dev eth0
ip route add 10.0.2.0/24 dev eth0
ip route add 10.0.3.0/24 dev eth0
ip route add 10.1.1.0/24 dev eth0
ip route add 192.168.1.0/24 dev eth0

#--------------------------------

hsl_install_6_docker-centos-quagga.sh

#------------------------------------------------------------------------------------------
# This tool (hsl_install_6_docker-centos-quagga.sh) is released under GNU GPL v2,v3
# Author: Tongguang Zhang
# Date: 2016-08-10
# first: install_docker-centos-quagga.txt
#------------------------------------------------------------------------------------------

#!/bin/sh

create_docker(){	

	# $1, that is, docker_node_num
	# $2, that is, docker_image

	# You will also have to make sure that your kernel has ethernet filtering (ebtables, bridge-nf,
	# arptables) disabled. If you do not do this, only STP and ARP traffic will be allowed to 
	# flow across your bridge and your whole scenario will not work.
	# if directory "/proc/sys/net/bridge" missing, I execute "modprobe br_netfilter" to get this directory again.

	if [ ! -d /proc/sys/net/bridge ]; then
		modprobe br_netfilter
	fi

	cd /proc/sys/net/bridge
	for f in bridge-nf-*; do echo 0 > $f; done
	cd -

	# [root@localhost ~]# man ip-netns
	# By convention a named network namespace is an object at /var/run/netns/NAME that can be opened.
	# The file descriptor resulting from opening /var/run/netns/NAME refers to the specified network
	# namespace. Holding that file descriptor open keeps the network namespace alive.
	# The file descriptor can be used with the setns(2) system
	# call to change the network namespace associated with a task.

	rm /var/run/netns -rf &>/dev/null
	mkdir -p /var/run/netns &>/dev/null

	# $1, that is, docker_node_num
	# $2, that is, docker_image
	#vm_image="$2"
	vm_image="centos_quagga"
	vmimage="centos:centos_quagga"

	for((id=1; id<=$1; id++))
	do

		# to determine whether docker_image exists
		exists=`docker images | awk -F \" '{print $1}' | grep ${vm_image} | wc -l | cat`
		if [ $exists -eq 0 ]; then
			echo "${vm_image} does not exist"
			exit
		fi

		# docker run -it --rm --net='none' --name "docker_${id}" centos-manet /bin/sh
		# gnome-terminal -x bash -c "docker run -it --rm --net='none' --name \"docker_${id}\" centos-manet /bin/sh"
		# gnome-terminal -x bash -c "docker run -it --rm --net='none' --name \"docker_${id}\" $2 /bin/sh"

		#gnome-terminal -x bash -c "docker run -it --rm --net='none' --name \"docker_${id}\" $2"
		# kernel network capabilities are not enabled by default.
		# You are going to need to run your container with --privileged
	#gnome-terminal -x bash -c "docker run --privileged -it -d --net='none' --name \"docker_${id}\" ${vm_image}"
		bash -c "docker run --privileged -it -d --net='none' --name \"docker_${id}\" ${vmimage}" &
		sleep 2

		# SET VARIABLES

		# get PID of CONTAINER
		pid=$(docker inspect -f '{{.State.Pid}}' "docker_${id}")

		bridge="br_r_${id}"
		brctl addbr ${bridge}

		#-----------------------------------------------------
		# router eth0
		#-----------------------------------------------------
		#bridge="br_r_${id}1"
		tap="tap_r_${id}1"
		veth="veth_r_${id}1"
		deth="deth_${id}1"

		#brctl addbr ${bridge}

		ip link add ${veth} type veth peer name ${deth}
		brctl addif ${bridge} ${veth}
		ip link set ${veth} up
		# ifconfig ${veth} 0.0.0.0 promisc up

		ip link set ${deth} netns ${pid}

		tunctl -t ${tap}
		ifconfig ${tap} up
		# ifconfig ${tap} promisc up
		# ifconfig ${tap} 0.0.0.0 promisc up

		brctl addif ${bridge} ${tap}
		ifconfig ${bridge} up
		# ifconfig ${bridge} promisc up
		# ifconfig ${bridge} 0.0.0.0 promisc up
		#-----------------------------------------------------

		#-----------------------------------------------------
		# router eth1
		#-----------------------------------------------------
		#bridge="br_r_${id}2"
		tap="tap_r_${id}2"
		veth="veth_r_${id}2"
		deth="deth_${id}2"

		#brctl addbr ${bridge}

		ip link add ${veth} type veth peer name ${deth}
		brctl addif ${bridge} ${veth}
		ip link set ${veth} up
		# ifconfig ${veth} 0.0.0.0 promisc up

		ip link set ${deth} netns ${pid}

		tunctl -t ${tap}
		ifconfig ${tap} up
		# ifconfig ${tap} promisc up
		# ifconfig ${tap} 0.0.0.0 promisc up

		brctl addif ${bridge} ${tap}
		ifconfig ${bridge} up
		# ifconfig ${bridge} promisc up
		# ifconfig ${bridge} 0.0.0.0 promisc up
		#-----------------------------------------------------

		ln -s /proc/${pid}/ns/net /var/run/netns/${pid}

		#-----------------------------------------------------
		# docker-1
		#-----------------------------------------------------
		if [ ${id} -eq 1 ]; then
			#-----------------------------------------------------
			# eth0
			#-----------------------------------------------------
			eth="eth0"
			ip="10.1.1.254"
			deth="deth_${id}1"
			ip netns exec ${pid} ip link set dev ${deth} name ${eth}
			ip netns exec ${pid} ip link set ${eth} up
			# ip netns exec ${pid} ip addr add 192.168.26.${id}/24 dev ${eth}
			ip netns exec ${pid} ip addr add ${ip}/24 dev ${eth}

			#-----------------------------------------------------
			# eth1
			#-----------------------------------------------------
			eth="eth1"
			ip="192.168.1.254"
			deth="deth_${id}2"
			ip netns exec ${pid} ip link set dev ${deth} name ${eth}
			ip netns exec ${pid} ip link set ${eth} up
			# ip netns exec ${pid} ip addr add 192.168.26.${id}/24 dev ${eth}
			ip netns exec ${pid} ip addr add ${ip}/24 dev ${eth}

			ip netns exec ${pid} ip route add 10.0.1.0/24 dev eth0
			ip netns exec ${pid} ip route add 10.0.2.0/24 dev eth0
			ip netns exec ${pid} ip route add 10.0.3.0/24 dev eth1
			ip netns exec ${pid} ip route add 10.0.4.0/24 dev eth1
			ip netns exec ${pid} ip route add 10.1.2.0/24 dev eth1
		fi

		#-----------------------------------------------------
		# docker-2
		#-----------------------------------------------------
		if [ ${id} -eq 2 ]; then
			#-----------------------------------------------------
			# eth0
			#-----------------------------------------------------
			eth="eth0"
			ip="192.168.1.253"
			deth="deth_${id}1"
			ip netns exec ${pid} ip link set dev ${deth} name ${eth}
			ip netns exec ${pid} ip link set ${eth} up
			# ip netns exec ${pid} ip addr add 192.168.26.${id}/24 dev ${eth}
			ip netns exec ${pid} ip addr add ${ip}/24 dev ${eth}

			#-----------------------------------------------------
			# eth1
			#-----------------------------------------------------
			eth="eth1"
			ip="10.1.2.254"
			deth="deth_${id}2"
			ip netns exec ${pid} ip link set dev ${deth} name ${eth}
			ip netns exec ${pid} ip link set ${eth} up
			# ip netns exec ${pid} ip addr add 192.168.26.${id}/24 dev ${eth}
			ip netns exec ${pid} ip addr add ${ip}/24 dev ${eth}

			ip netns exec ${pid} ip route add 10.0.1.0/24 dev eth0
			ip netns exec ${pid} ip route add 10.0.2.0/24 dev eth0
			ip netns exec ${pid} ip route add 10.0.3.0/24 dev eth1
			ip netns exec ${pid} ip route add 10.0.4.0/24 dev eth1
			ip netns exec ${pid} ip route add 10.1.1.0/24 dev eth0
		fi

		#-----------------------------------------------------
		# docker-3
		#-----------------------------------------------------
		if [ ${id} -eq 3 ]; then
			#-----------------------------------------------------
			# eth0
			#-----------------------------------------------------
			eth="eth0"
			ip="10.1.1.253"
			deth="deth_${id}1"
			ip netns exec ${pid} ip link set dev ${deth} name ${eth}
			ip netns exec ${pid} ip link set ${eth} up
			# ip netns exec ${pid} ip addr add 192.168.26.${id}/24 dev ${eth}
			ip netns exec ${pid} ip addr add ${ip}/24 dev ${eth}

			#-----------------------------------------------------
			# eth1
			#-----------------------------------------------------
			eth="eth1"
			ip="10.0.1.254"
			deth="deth_${id}2"
			ip netns exec ${pid} ip link set dev ${deth} name ${eth}
			ip netns exec ${pid} ip link set ${eth} up
			# ip netns exec ${pid} ip addr add 192.168.26.${id}/24 dev ${eth}
			ip netns exec ${pid} ip addr add ${ip}/24 dev ${eth}

			ip netns exec ${pid} ip route add 10.0.2.0/24 dev eth0
			ip netns exec ${pid} ip route add 10.0.3.0/24 dev eth0
			ip netns exec ${pid} ip route add 10.0.4.0/24 dev eth0
			ip netns exec ${pid} ip route add 10.1.2.0/24 dev eth0
			ip netns exec ${pid} ip route add 192.168.1.0/24 dev eth0
		fi

		#-----------------------------------------------------
		# docker-4
		#-----------------------------------------------------
		if [ ${id} -eq 4 ]; then
			#-----------------------------------------------------
			# eth0
			#-----------------------------------------------------
			eth="eth0"
			ip="10.1.1.252"
			deth="deth_${id}1"
			ip netns exec ${pid} ip link set dev ${deth} name ${eth}
			ip netns exec ${pid} ip link set ${eth} up
			# ip netns exec ${pid} ip addr add 192.168.26.${id}/24 dev ${eth}
			ip netns exec ${pid} ip addr add ${ip}/24 dev ${eth}

			#-----------------------------------------------------
			# eth1
			#-----------------------------------------------------
			eth="eth1"
			ip="10.0.2.254"
			deth="deth_${id}2"
			ip netns exec ${pid} ip link set dev ${deth} name ${eth}
			ip netns exec ${pid} ip link set ${eth} up
			# ip netns exec ${pid} ip addr add 192.168.26.${id}/24 dev ${eth}
			ip netns exec ${pid} ip addr add ${ip}/24 dev ${eth}

			ip netns exec ${pid} ip route add 10.0.1.0/24 dev eth0
			ip netns exec ${pid} ip route add 10.0.3.0/24 dev eth0
			ip netns exec ${pid} ip route add 10.0.4.0/24 dev eth0
			ip netns exec ${pid} ip route add 10.1.2.0/24 dev eth0
			ip netns exec ${pid} ip route add 192.168.1.0/24 dev eth0
		fi

		#-----------------------------------------------------
		# docker-5
		#-----------------------------------------------------
		if [ ${id} -eq 5 ]; then
			#-----------------------------------------------------
			# eth0
			#-----------------------------------------------------
			eth="eth0"
			ip="10.1.2.253"
			deth="deth_${id}1"
			ip netns exec ${pid} ip link set dev ${deth} name ${eth}
			ip netns exec ${pid} ip link set ${eth} up
			# ip netns exec ${pid} ip addr add 192.168.26.${id}/24 dev ${eth}
			ip netns exec ${pid} ip addr add ${ip}/24 dev ${eth}

			#-----------------------------------------------------
			# eth1
			#-----------------------------------------------------
			eth="eth1"
			ip="10.0.3.254"
			deth="deth_${id}2"
			ip netns exec ${pid} ip link set dev ${deth} name ${eth}
			ip netns exec ${pid} ip link set ${eth} up
			# ip netns exec ${pid} ip addr add 192.168.26.${id}/24 dev ${eth}
			ip netns exec ${pid} ip addr add ${ip}/24 dev ${eth}

			ip netns exec ${pid} ip route add 10.0.1.0/24 dev eth0
			ip netns exec ${pid} ip route add 10.0.2.0/24 dev eth0
			ip netns exec ${pid} ip route add 10.0.4.0/24 dev eth0
			ip netns exec ${pid} ip route add 10.1.1.0/24 dev eth0
			ip netns exec ${pid} ip route add 192.168.1.0/24 dev eth0
		fi

		#-----------------------------------------------------
		# docker-6
		#-----------------------------------------------------
		if [ ${id} -eq 6 ]; then
			#-----------------------------------------------------
			# eth0
			#-----------------------------------------------------
			eth="eth0"
			ip="10.1.2.252"
			deth="deth_${id}1"
			ip netns exec ${pid} ip link set dev ${deth} name ${eth}
			ip netns exec ${pid} ip link set ${eth} up
			# ip netns exec ${pid} ip addr add 192.168.26.${id}/24 dev ${eth}
			ip netns exec ${pid} ip addr add ${ip}/24 dev ${eth}

			#-----------------------------------------------------
			# eth1
			#-----------------------------------------------------
			eth="eth1"
			ip="10.0.4.254"
			deth="deth_${id}2"
			ip netns exec ${pid} ip link set dev ${deth} name ${eth}
			ip netns exec ${pid} ip link set ${eth} up
			# ip netns exec ${pid} ip addr add 192.168.26.${id}/24 dev ${eth}
			ip netns exec ${pid} ip addr add ${ip}/24 dev ${eth}

			ip netns exec ${pid} ip route add 10.0.1.0/24 dev eth0
			ip netns exec ${pid} ip route add 10.0.2.0/24 dev eth0
			ip netns exec ${pid} ip route add 10.0.3.0/24 dev eth0
			ip netns exec ${pid} ip route add 10.1.1.0/24 dev eth0
			ip netns exec ${pid} ip route add 192.168.1.0/24 dev eth0
		fi

		#-----------------------------------------------------
		# quagga, // not use quagga, setup routing table manually
		#-----------------------------------------------------
#		docker exec docker_${id} /bin/sh -c "sed -i '24a \ router-id 10.1.1.${id}' /etc/quagga/ospf6d.conf"
#		docker exec docker_${id} /bin/sh -c "zebra -d &>/dev/null"
#		docker exec docker_${id} /bin/sh -c "ospf6d -d &>/dev/null"

	done
}

#------------------------------------------------------------------------------------------
# function destroy_docker()
# Description:
# destroy $docker_node_num of dockers
# receive one parameter, that is docker_node_num
#------------------------------------------------------------------------------------------

destroy_docker(){

	# $1, that is, $docker_node_num
	for((id=1; id<=$1; id++))
	do
		bridge="br_r_${id}"

		#-----------------------------------------------------
		# router eth0
		#-----------------------------------------------------
		#bridge="br_r_${id}1"
		tap="tap_r_${id}1"
		veth="veth_r_${id}1"

		ifconfig ${bridge} down &>/dev/null
		brctl delif ${bridge} ${tap} &>/dev/null
		#brctl delbr ${bridge} &>/dev/null

		ifconfig ${tap} down &>/dev/null
		tunctl -d ${tap} &>/dev/null
		ifconfig ${veth} down &>/dev/null
		#-----------------------------------------------------

		#-----------------------------------------------------
		# router eth1
		#-----------------------------------------------------
		#bridge="br_r_${id}2"
		tap="tap_r_${id}2"
		veth="veth_r_${id}2"

		#ifconfig ${bridge} down &>/dev/null
		brctl delif ${bridge} ${tap} &>/dev/null
		brctl delbr ${bridge} &>/dev/null

		ifconfig ${tap} down &>/dev/null
		tunctl -d ${tap} &>/dev/null
		ifconfig ${veth} down &>/dev/null
		#-----------------------------------------------------

		docker stop "docker_${id}" &>/dev/null
		docker rm "docker_${id}" &>/dev/null
	done
}

# ./hsl_install_6_docker-centos-quagga.sh para1
# para1 ($1), that is, the value is create or destroy

if [ $# -eq 1 ]; then

	if !([ $1 == "create" ]||[ $1 == "destroy" ]); then
		echo "usage: ./hsl_install_6_docker-centos-quagga.sh para1"
		exit
	fi

	case $1 in
		create)
			create_docker 6
		;;
		destroy)
			destroy_docker 6
		;;
	esac
else
	echo "usage: ./hsl_install_6_docker-centos-quagga.sh create"
	echo "usage: ./hsl_install_6_docker-centos-quagga.sh destroy"
fi

#-------------------------------------------------
# docker run --privileged -it -d --name "docker_1" centos-manet
# docker ps -a
# docker attach docker_1
# docker stop docker_1
# docker rm docker_1
#-------------------------------------------------

/opt/tools/network_simulators/ns3/ns-allinone-3.25/ns-3.25/scratch/seem-6-win7-switch-docker.cc

/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
 * Copyright (c) 2015 - Chip Webb
 *
 * 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
 *
 * Author: Chip Webb  <ns3 (at) chipwebb.com>
 *
 */

#include <iostream>
#include <fstream>

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

using namespace ns3;

// ########################################################################
// Main routine
// ########################################################################
NS_LOG_COMPONENT_DEFINE ("GlobalRoutingMultiSwitchPlusRouter");

#define vssearch(loc,vec) std::find ((vec).begin (), (vec).end (), (loc)) != (vec).end ()

int
main (int argc, char *argv[])
{
  // ----------------------------------------------------------------------
  // Default values for command line arguments
  // ----------------------------------------------------------------------
  bool        verbose              = true;

  int         simDurationSeconds   = 60;

  bool        enableUdpMultiSW     = true;
  bool        enableUdpSingleSW    = true;

  std::string pcapLocations        = "";
  uint32_t    snapLen              = PcapFile::SNAPLEN_DEFAULT;

  std::string csmaXLinkDataRate    = "100Mbps";
  std::string csmaXLinkDelay       = "500ns";

  std::string csmaYLinkDataRate    = "10Mbps";
  std::string csmaYLinkDelay       = "500ns";

//  uint16_t    udpEchoPort          = 9;  // The well-known UDP echo port


  // ----------------------------------------------------------------------
  // Create command line options and get them
  // ----------------------------------------------------------------------
  CommandLine cmd;

  cmd.Usage    ("NOTE: valid --pcap arguments are: 't2,t3,b2,b3,trlan,trwan,brlan,brwan'");

  cmd.AddValue ("verbose",      "Enable printing informational messages",        verbose);

  cmd.AddValue ("duration",     "Duration of simulation.",                       simDurationSeconds);

  cmd.AddValue ("udpMultiSW",   "Enable udp over multi-switch links",            enableUdpMultiSW);
  cmd.AddValue ("udpSingleSW",  "Enable udp over single-switch links",           enableUdpSingleSW);

  cmd.AddValue ("pcap",         "Comma separated list of PCAP Locations to tap", pcapLocations);
  cmd.AddValue ("snapLen",      "PCAP packet capture length",                    snapLen);

  cmd.AddValue ("csmaXRate",    "CSMA X Link data rate",                         csmaXLinkDataRate);
  cmd.AddValue ("csmaXDelay",   "CSMA X Link delay",                             csmaXLinkDelay);

  cmd.AddValue ("csmaYRate",    "CSMA Y Link data rate",                         csmaYLinkDataRate);
  cmd.AddValue ("csmaYDelay",   "CSMA Y Link delay",                             csmaYLinkDelay);

  cmd.Parse (argc, argv);

  // --------------------------------------------------------------------
  // Users may find it convenient to turn on explicit debugging
  // for selected modules; the below lines suggest how to do this
  // --------------------------------------------------------------------
  if (verbose)
    {
      LogComponentEnable ("GlobalRoutingMultiSwitchPlusRouter", LOG_LEVEL_INFO);
    }


  // ======================================================================
  // Define the list of valid PCAP taps
  // ----------------------------------------------------------------------
//  std::vector<std::string> pcapTaps;
//  pcapTaps.push_back ("t2");              // multi-switch  UDP echo client
//  pcapTaps.push_back ("t3");              // single-switch UDP echo server
//  pcapTaps.push_back ("b2");              // multi-switch  UDP echo server
//  pcapTaps.push_back ("b3");              // single-switch UDP echo client
//  pcapTaps.push_back ("trlan");           // top router    LAN side
//  pcapTaps.push_back ("trwan");           // top router    WAN side
//  pcapTaps.push_back ("brlan");           // bottom router LAN side
//  pcapTaps.push_back ("brwan");           // bottom router WAN side

  // ----------------------------------------------------------------------
  // Parse the pcapLocations string into pcapLocationVec
  // ----------------------------------------------------------------------
/*
  std::vector<std::string> pcapLocationVec;
  if (pcapLocations != "")
    {
      std::stringstream sStream (pcapLocations);

      while ( sStream.good () )
        {
          std::string substr;
          getline ( sStream, substr, ',' );
          if (vssearch (substr,pcapTaps))
            {
              pcapLocationVec.push_back ( substr );
            }
          else
            {
              NS_LOG_ERROR ("WARNING: Unrecognized PCAP location: <" + substr + ">");
            }
        }

      for (std::vector<std::string>::const_iterator
           ploc = pcapLocationVec.begin ();
           ploc  != pcapLocationVec.end ();
           ++ploc)
        {
          NS_LOG_INFO ("PCAP capture at: <" + *ploc + ">");
        }
    }
*/
  // ======================================================================
  // Set some simulator-wide values
  // ======================================================================

  // ----------------------------------------------------------------------
  // Set PCAP packet capture maximum packet length
  // ----------------------------------------------------------------------
/*
  if (snapLen != PcapFile::SNAPLEN_DEFAULT)
  {
      Config::SetDefault ("ns3::PcapFileWrapper::CaptureSize",   UintegerValue (snapLen));
  }
*/
  // ======================================================================
  // Create the nodes & links required for the topology shown in comments above.
  // ----------------------------------------------------------------------
  NS_LOG_INFO ("INFO: Create nodes.");

  // use docker as router, there 6 routers (dockers) totally
  // every docker has two net interfaces, namely, eth0 & eth1
  NodeContainer router_nodes;
  router_nodes.Create (12);

  NodeContainer pc_nodes;
  pc_nodes.Create (4);

  NodeContainer ser_nodes;
  ser_nodes.Create (2);

  Ptr<Node> ts1 = CreateObject<Node> ();  // <no IP>     : Top switch #1 (bridge)
  Ptr<Node> ts2 = CreateObject<Node> ();  // <no IP>     : Top switch #2 (bridge)

  Ptr<Node> bs1 = CreateObject<Node> ();  // <no IP>     : Bottom switch #1 (bridge)
  Ptr<Node> bs2 = CreateObject<Node> ();  // <no IP>     : Bottom switch #2 (bridge)
  Ptr<Node> bs3 = CreateObject<Node> ();  // <no IP>     : Bottom switch #3 (bridge)
  Ptr<Node> bs4 = CreateObject<Node> ();  // <no IP>     : Bottom switch #4 (bridge)

  // ----------------------------------------------------------------------
  // Give the nodes names
  // ----------------------------------------------------------------------
//  Names::Add ("t2",  t2);
//  Names::Add ("t3",  t3);
//  Names::Add ("ts1", ts1);
//  Names::Add ("ts2", ts2);

//  Names::Add ("bs1", bs1);
//  Names::Add ("bs2", bs2);
//  Names::Add ("bs3", bs3);
//  Names::Add ("bs4", bs4);
//  Names::Add ("b2",  b2);
//  Names::Add ("b3",  b3);

  // ======================================================================
  // Create CSMA links to use for connecting LAN nodes together
  // ----------------------------------------------------------------------

  // ----------------------------------------
  // CSMA [X]
  // ----------------------------------------
  NS_LOG_INFO ("L2: Create a " <<
               csmaXLinkDataRate << " " <<
               csmaXLinkDelay << " CSMA link for csmaX for LANs.");
  CsmaHelper csmaX;
  csmaX.SetChannelAttribute ("DataRate", StringValue (csmaXLinkDataRate));
  csmaX.SetChannelAttribute ("Delay",    StringValue (csmaXLinkDelay));

  // ----------------------------------------
  // CSMA [Y]
  // ----------------------------------------
  NS_LOG_INFO ("L2: Create a " <<
               csmaYLinkDataRate << " " <<
               csmaYLinkDelay << " CSMA link for csmaY for LANs.");
  CsmaHelper csmaY;
  csmaY.SetChannelAttribute ("DataRate", StringValue (csmaYLinkDataRate));
  csmaY.SetChannelAttribute ("Delay",    StringValue (csmaYLinkDelay));

  // ----------------------------------------------------------------------
  // Now, connect the top LAN nodes together with csma links.
  // ----------------------------------------------------------------------
  NS_LOG_INFO ("L2: Connect nodes on top LAN together with half-duplex CSMA links.");

  // Multi-switch top LAN chain: t2-ts4-ts3-ts2-ts1-tr

  // docker1 <---> docker2
  NetDeviceContainer link_r1_r2   = csmaX.Install (NodeContainer (router_nodes.Get(1), router_nodes.Get(2)));

  // ts1
  NetDeviceContainer link_ts1_r0   = csmaX.Install (NodeContainer (ts1, router_nodes.Get(0)));
  NetDeviceContainer link_ts1_r4   = csmaX.Install (NodeContainer (ts1, router_nodes.Get(4)));
  NetDeviceContainer link_ts1_r6   = csmaX.Install (NodeContainer (ts1, router_nodes.Get(6)));
  NetDeviceContainer link_ts1_s0   = csmaX.Install (NodeContainer (ts1, ser_nodes.Get(0)));

  // ts2
  NetDeviceContainer link_ts2_r3   = csmaX.Install (NodeContainer (ts2, router_nodes.Get(3)));
  NetDeviceContainer link_ts2_r8   = csmaX.Install (NodeContainer (ts2, router_nodes.Get(8)));
  NetDeviceContainer link_ts2_r10   = csmaX.Install (NodeContainer (ts2, router_nodes.Get(10)));
  NetDeviceContainer link_ts2_s1   = csmaX.Install (NodeContainer (ts2, ser_nodes.Get(1)));

  // bs1
  NetDeviceContainer link_bs1_r5   = csmaX.Install (NodeContainer (bs1, router_nodes.Get(5)));
  NetDeviceContainer link_bs1_p0   = csmaX.Install (NodeContainer (bs1, pc_nodes.Get(0)));

  // bs2
  NetDeviceContainer link_bs2_r7   = csmaX.Install (NodeContainer (bs2, router_nodes.Get(7)));
  NetDeviceContainer link_bs2_p1   = csmaX.Install (NodeContainer (bs2, pc_nodes.Get(1)));

  // bs3
  NetDeviceContainer link_bs3_r9   = csmaX.Install (NodeContainer (bs3, router_nodes.Get(9)));
  NetDeviceContainer link_bs3_p2   = csmaX.Install (NodeContainer (bs3, pc_nodes.Get(2)));

  // bs4
  NetDeviceContainer link_bs4_r11   = csmaX.Install (NodeContainer (bs4, router_nodes.Get(11)));
  NetDeviceContainer link_bs4_p3   = csmaX.Install (NodeContainer (bs4, pc_nodes.Get(3)));

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

  // Top Switch 1 NetDevices (ts1)
  NetDeviceContainer ts1nd;
  ts1nd.Add (link_ts1_r0.Get (0));
  ts1nd.Add (link_ts1_r4.Get (0));
  ts1nd.Add (link_ts1_r6.Get (0));
  ts1nd.Add (link_ts1_s0.Get (0));

  // Top Switch 2 NetDevices (ts2)
  NetDeviceContainer ts2nd;
  ts2nd.Add (link_ts2_r3.Get (0));
  ts2nd.Add (link_ts2_r8.Get (0));
  ts2nd.Add (link_ts2_r10.Get (0));
  ts2nd.Add (link_ts2_s1.Get (0));

  // Bottom Switch 1 NetDevices (bs1)
  NetDeviceContainer bs1nd;
  bs1nd.Add (link_bs1_r5.Get (0));
  bs1nd.Add (link_bs1_p0.Get (0));

  // Bottom Switch 2 NetDevices (bs2)
  NetDeviceContainer bs2nd;
  bs2nd.Add (link_bs2_r7.Get (0));
  bs2nd.Add (link_bs2_p1.Get (0));

  // Bottom Switch 3 NetDevices (bs3)
  NetDeviceContainer bs3nd;
  bs3nd.Add (link_bs3_r9.Get (0));
  bs3nd.Add (link_bs3_p2.Get (0));

  // Bottom Switch 4 NetDevices (bs4)
  NetDeviceContainer bs4nd;
  bs4nd.Add (link_bs4_r11.Get (0));
  bs4nd.Add (link_bs4_p3.Get (0));

  // ======================================================================
  // Install bridging code on each switch
  // ----------------------------------------------------------------------
  BridgeHelper bridge;

  bridge.Install (ts1, ts1nd);
  bridge.Install (ts2, ts2nd);

  bridge.Install (bs1, bs1nd);
  bridge.Install (bs2, bs2nd);
  bridge.Install (bs3, bs3nd);
  bridge.Install (bs4, bs4nd);

  // ======================================================================
  // link Linux bridge
  // ----------------------------------------------------------------------
  NetDeviceContainer RouterNodes;
  NetDeviceContainer PcNodes;
  NetDeviceContainer SerNodes;

  RouterNodes.Add (link_ts1_r0.Get (1));
  RouterNodes.Add (link_r1_r2.Get (0));
  RouterNodes.Add (link_r1_r2.Get (1));
  RouterNodes.Add (link_ts2_r3.Get (1));
  RouterNodes.Add (link_ts1_r4.Get (1));
  RouterNodes.Add (link_bs1_r5.Get (1));
  RouterNodes.Add (link_ts1_r6.Get (1));
  RouterNodes.Add (link_bs2_r7.Get (1));
  RouterNodes.Add (link_ts2_r8.Get (1));
  RouterNodes.Add (link_bs3_r9.Get (1));
  RouterNodes.Add (link_ts2_r10.Get (1));
  RouterNodes.Add (link_bs4_r11.Get (1));

  PcNodes.Add (link_bs1_p0.Get (1));
  PcNodes.Add (link_bs2_p1.Get (1));
  PcNodes.Add (link_bs3_p2.Get (1));
  PcNodes.Add (link_bs4_p3.Get (1));

  SerNodes.Add (link_ts1_s0.Get (1));
  SerNodes.Add (link_ts2_s1.Get (1));

  // ======================================================================
  // link VM.
  // ----------------------------------------------------------------------

  TapBridgeHelper tapBridge;
  tapBridge.SetAttribute ("Mode", StringValue ("UseBridge"));

  // PC Node 0, 1, 2, 3
  tapBridge.SetAttribute ("DeviceName", StringValue ("tap_w_1"));
  tapBridge.Install (pc_nodes.Get (0), PcNodes.Get (0));   //p0

  tapBridge.SetAttribute ("DeviceName", StringValue ("tap_w_2"));
  tapBridge.Install (pc_nodes.Get (1), PcNodes.Get (1));   //p1

  tapBridge.SetAttribute ("DeviceName", StringValue ("tap_w_3"));
  tapBridge.Install (pc_nodes.Get (2), PcNodes.Get (2));   //p2

  tapBridge.SetAttribute ("DeviceName", StringValue ("tap_w_4"));
  tapBridge.Install (pc_nodes.Get (3), PcNodes.Get (3));   //p3

  // Ser Node 0, 1
  tapBridge.SetAttribute ("DeviceName", StringValue ("tap_w_5"));
  tapBridge.Install (ser_nodes.Get (0), SerNodes.Get (0));   //s0

  tapBridge.SetAttribute ("DeviceName", StringValue ("tap_w_6"));
  tapBridge.Install (ser_nodes.Get (1), SerNodes.Get (1));   //s1

  // Router Node 0 ~ 11
  tapBridge.SetAttribute ("DeviceName", StringValue ("tap_r_11"));
  tapBridge.Install (router_nodes.Get (0), RouterNodes.Get (0));   //r0, docker_1

  tapBridge.SetAttribute ("DeviceName", StringValue ("tap_r_12"));
  tapBridge.Install (router_nodes.Get (1), RouterNodes.Get (1));   //r1, docker_1

  tapBridge.SetAttribute ("DeviceName", StringValue ("tap_r_21"));
  tapBridge.Install (router_nodes.Get (2), RouterNodes.Get (2));   //r2, docker_2

  tapBridge.SetAttribute ("DeviceName", StringValue ("tap_r_22"));
  tapBridge.Install (router_nodes.Get (3), RouterNodes.Get (3));   //r3, docker_2

  tapBridge.SetAttribute ("DeviceName", StringValue ("tap_r_31"));
  tapBridge.Install (router_nodes.Get (4), RouterNodes.Get (4));   //r4, docker_3

  tapBridge.SetAttribute ("DeviceName", StringValue ("tap_r_32"));
  tapBridge.Install (router_nodes.Get (5), RouterNodes.Get (5));   //r5, docker_3

  tapBridge.SetAttribute ("DeviceName", StringValue ("tap_r_41"));
  tapBridge.Install (router_nodes.Get (6), RouterNodes.Get (6));   //r6, docker_4

  tapBridge.SetAttribute ("DeviceName", StringValue ("tap_r_42"));
  tapBridge.Install (router_nodes.Get (7), RouterNodes.Get (7));   //r7, docker_4

  tapBridge.SetAttribute ("DeviceName", StringValue ("tap_r_51"));
  tapBridge.Install (router_nodes.Get (8), RouterNodes.Get (8));   //r8, docker_5

  tapBridge.SetAttribute ("DeviceName", StringValue ("tap_r_52"));
  tapBridge.Install (router_nodes.Get (9), RouterNodes.Get (9));   //r9, docker_5

  tapBridge.SetAttribute ("DeviceName", StringValue ("tap_r_61"));
  tapBridge.Install (router_nodes.Get (10), RouterNodes.Get (10));   //r10, docker_6

  tapBridge.SetAttribute ("DeviceName", StringValue ("tap_r_62"));
  tapBridge.Install (router_nodes.Get (11), RouterNodes.Get (11));   //r11, docker_6

  // ======================================================================
  // Now, do the actual simulation.
  // ----------------------------------------------------------------------
//  NS_LOG_INFO ("Run Simulation for " << simDurationSeconds << " seconds.");
//  Simulator::Stop (Seconds (simDurationSeconds));

  Simulator::Run ();
  Simulator::Destroy ();
  NS_LOG_INFO ("Done.");

}











posted @ 2016-08-10 16:58  张同光  阅读(142)  评论(0编辑  收藏  举报