Ejemplo n.º 1
0
def run():
    Minindn.cleanUp()
    Minindn.verifyDependencies()
    topo = Topo()
    # Setup topo
    info("Setup\n")
    a = topo.addHost('a')
    b = topo.addHost('b')
    c = topo.addHost('c')
    topo.addLink(a, b, delay='10ms', bw=10)
    topo.addLink(b, c, delay='10ms', bw=10)
    ndn = Minindn(topo=topo)
    ndn.start()
    info("Configuring NFD\n")
    nfds = AppManager(ndn, ndn.net.hosts, Nfd, logLevel="DEBUG")
    #nlsr = AppManager(ndn, ndn.net.hosts, Nlsr, logLevel="DEBUG")
    # This is a fancy way of setting up the routes without violating DRY;
    # the important bit to note is the Nfdc command
    links = {"a": ["b"], "b": ["c"]}
    for first in links:
        for second in links[first]:
            host1 = ndn.net[first]
            host2 = ndn.net[second]
            interface = host2.connectionsTo(host1)[0][0]
            #info(interface)
            interface_ip = interface.IP()
            Nfdc.createFace(host1, interface_ip)
            Nfdc.registerRoute(host1, PREFIX, interface_ip, cost=0)
    info("Starting pings...\n")
    pingserver_log = open("/tmp/minindn/c/ndnpingserver.log", "w")
    pingserver = getPopen(ndn.net["c"],
                          "ndnpingserver {}".format(PREFIX),
                          stdout=pingserver_log,
                          stderr=pingserver_log)
    ping1 = getPopen(ndn.net["a"],
                     "ndnping {} -c 5".format(PREFIX),
                     stdout=PIPE,
                     stderr=PIPE)
    ping1.wait()
    info(ping1.stdout.read())
    interface = ndn.net["b"].connectionsTo(ndn.net["a"])[0][0]
    info("Failing link\n")
    interface.config(delay="10ms", bw=10, loss=100)
    ping2 = getPopen(ndn.net["a"],
                     "ndnping {} -c 5".format(PREFIX),
                     stdout=PIPE,
                     stderr=PIPE)
    ping2.wait()
    info(ping2.stdout.read())
    interface.config(delay="10ms", bw=10, loss=0)
    MiniNDNCLI(ndn.net)
    info("Finished!\n")
    ndn.stop()
Ejemplo n.º 2
0
# If not, see <http://www.gnu.org/licenses/>.

from mininet.log import setLogLevel, info

from minindn.minindn import Minindn
from minindn.apps.app_manager import AppManager
from minindn.util import MiniNDNCLI
from minindn.apps.nfd import Nfd
from minindn.apps.nlsr import Nlsr
from minindn.apps.tshark import Tshark

if __name__ == '__main__':
    setLogLevel('info')

    Minindn.cleanUp()
    Minindn.verifyDependencies()

    ndn = Minindn()

    ndn.start()

    info('Starting tshark logging on nodes\n')
    tshark = AppManager(ndn, ndn.net.hosts, Tshark, logFolder="./log/")

    info('Starting NFD on nodes\n')
    nfds = AppManager(ndn, ndn.net.hosts, Nfd)
    info('Starting NLSR on nodes\n')
    nlsrs = AppManager(ndn, ndn.net.hosts, Nlsr)

    MiniNDNCLI(ndn.net)
Ejemplo n.º 3
0
def runExperiment(strTopoPath, lstDataQueue, bWifi=True):
    """
   Runs the experiment using regular MiniNDN
   """
    global g_bShowMiniNDNCli, g_bSDNEnabled
    logging.info('[runExperiment] Running MiniNDN experiment')

    if (bWifi):
        MiniNDNClass = MinindnWifi
    else:
        MiniNDNClass = Minindn

    Minindn.cleanUp()
    Minindn.verifyDependencies()

    ######################################################
    # Start MiniNDN and set controller, if any
    if (g_bSDNEnabled):
        ndn = MiniNDNClass(topoFile=strTopoPath, controller=RemoteController)
    else:
        ndn = MiniNDNClass(topoFile=strTopoPath)

    ndn.start()

    # Wifi topology uses stations instead of hosts, the idea is the same
    if (bWifi):
        lstHosts = ndn.net.stations + ndn.net.hosts

        # for pStation in ndn.net.stations:
        #    strIP = pStation.IP() + '/24'
        #    setStationIPs(pStation, strIP)
        #    logging.info('[runExperiment] station=%s, IP=%s' % (str(pStation), strIP))

        if (ndn.net.aps is not None) and (len(ndn.net.aps) > 0):
            # Connect all APs to the remote controller
            # This should be done regardless of SDN, otherwise packets will not be routed
            logging.info('[runExperiment] Setting up access points...')
            nApId = 1
            for pAp in ndn.net.aps:
                strApId = '1000000000' + str(nApId).zfill(6)
                subprocess.call([
                    'ovs-vsctl', 'set-controller',
                    str(pAp), 'tcp:127.0.0.1:6633'
                ])
                subprocess.call([
                    'ovs-vsctl', 'set', 'bridge',
                    str(pAp), 'other-config:datapath-id=' + strApId
                ])
                nApId += 1

                # TODO: Add priority based rules to APs if g_bSDNEnabled
                # ovs-ofctl add-flow <ap_name> dl_type=0x0800
    else:
        lstHosts = ndn.net.hosts

    #######################################################
    # Initialize NFD and set cache size based on host type
    logging.info('[runExperiment] Starting NFD on nodes')
    lstHumanHosts = []
    lstDroneHosts = []
    lstSensorHosts = []
    lstVehicleHosts = []
    for pHost in lstHosts:
        if (pHost.name[0] == 'h'):
            lstHumanHosts.append(pHost)
        elif (pHost.name[0] == 'd'):
            lstDroneHosts.append(pHost)
        elif (pHost.name[0] == 's'):
            lstSensorHosts.append(pHost)
        elif (pHost.name[0] == 'v'):
            lstVehicleHosts.append(pHost)
        else:
            raise Exception(
                '[runExperiment] Hostname=%s not recognized as human, drone, sensor or vehicle'
                % pHost.name)

    nfdsHuman = AppManager(ndn,
                           lstHumanHosts,
                           Nfd,
                           csSize=c_nHumanCacheSize,
                           logLevel=c_strNFDLogLevel)
    logging.info('[runExperiment] Cache set for humans=%d, size=%d' %
                 (len(lstHumanHosts), c_nHumanCacheSize))
    nfdsDrone = AppManager(ndn,
                           lstDroneHosts,
                           Nfd,
                           csSize=c_nDroneCacheSize,
                           logLevel=c_strNFDLogLevel)
    logging.info('[runExperiment] Cache set for drones=%d, size=%d' %
                 (len(lstDroneHosts), c_nDroneCacheSize))
    nfdsSensor = AppManager(ndn,
                            lstSensorHosts,
                            Nfd,
                            csSize=c_nSensorCacheSize,
                            logLevel=c_strNFDLogLevel)
    logging.info('[runExperiment] Cache set for sensors=%d, size=%d' %
                 (len(lstSensorHosts), c_nSensorCacheSize))
    nfdsVehicle = AppManager(ndn,
                             lstVehicleHosts,
                             Nfd,
                             csSize=c_nVehicleCacheSize,
                             logLevel=c_strNFDLogLevel)
    logging.info('[runExperiment] Cache set for vehicles=%d, size=%d' %
                 (len(lstVehicleHosts), c_nVehicleCacheSize))

    # Advertise faces
    logging.info('[runExperiment] Setting up faces for %d hosts' %
                 len(lstHosts))
    for pHostOrig in lstHosts:
        for pHostDest in lstHosts:
            if (pHostDest != pHostOrig):
                logging.debug(
                    '[runExperiment] Register, pHostOrig=%s; pHostDest=%s' %
                    (str(pHostOrig), str(pHostDest)))
                Nfdc.createFace(pHostOrig, pHostDest.IP())
                Nfdc.registerRoute(
                    pHostOrig, RandomTalks.getFilterByHostname(str(pHostDest)),
                    pHostDest.IP())

    if (not bWifi):
        ##########################################################
        # Initialize NLSR
        logging.info('[runExperiment] Starting NLSR on nodes')
        nlsrs = AppManager(ndn, lstHosts, Nlsr, logLevel=c_strNLSRLogLevel)

        ##########################################################
        # Wait for NLSR initialization, at least 30 seconds to be on the safe side
        logging.info('[runExperiment] NLSR sleep set to %d seconds' %
                     c_nNLSRSleepSec)
        time.sleep(c_nNLSRSleepSec)

    ##########################################################
    # Set up and run experiment
    logging.info('[runExperiment] Begin experiment')
    Experiment = RandomTalks(lstHosts, lstDataQueue)
    try:
        logging.info('[runExperiment] Running pingall ...')
        # ndn.net.pingAll()
        logging.info('[runExperiment] Pingall done')
        Experiment.setup()
        (dtBegin, dtEnd) = Experiment.run()
    except Exception as e:
        logging.error(
            '[runExperiment] An exception was raised during the experiment: %s'
            % str(e))
        raise

    logging.info(
        '[runExperiment] End of experiment, TimeElapsed=%s; KBytesConsumed=%.2f'
        % (str(dtEnd - dtBegin), float(Experiment.nBytesConsumed) / 1024))

    if (g_bShowMiniNDNCli):
        if (bWifi):
            MiniNDNWifiCLI(ndn.net)
        else:
            MiniNDNCLI(ndn.net)
    ndn.stop()
Ejemplo n.º 4
0
def run():
    PREFIX = "/ndn/test/"
    Minindn.cleanUp()
    Minindn.verifyDependencies()
    topo = Topo()
    # Setup topo
    print("Setup")
    c1 = topo.addHost('c1')
    i1 = topo.addHost('i1')

    i2 = topo.addHost('i2')
    i3 = topo.addHost('i3')
    i4 = topo.addHost('i4')
    i5 = topo.addHost('i5')

    i6 = topo.addHost('i6')
    p1 = topo.addHost('p1')

    topo.addLink(c1, i1, bw=10)

    topo.addLink(i1, i2, bw=4, delay='40ms')
    topo.addLink(i1, i3, bw=4, delay='10ms')
    topo.addLink(i1, i4, bw=4, delay='40ms')
    topo.addLink(i1, i5, bw=4, delay='40ms')

    topo.addLink(i2, i6, bw=7, delay='7ms')
    topo.addLink(i3, i6, bw=7, delay='7ms')
    topo.addLink(i4, i6, bw=7, delay='7ms')
    topo.addLink(i5, i6, bw=7, delay='7ms')

    topo.addLink(i6, p1, bw=10)
    ndn = Minindn(topo=topo)
    ndn.start()
    nfds = AppManager(ndn, ndn.net.hosts, Nfd)
    # Setup routes to C2
    # This is not functional but I'm saving this as an example for the future :)
    # for host1 in ndn.net.hosts:
    #     for host2 in ndn.net.hosts:
    #         if 'p' in host1.name and not 'p' in host2.name:
    #             return
    #         elif 'i' in host1.name and 'c' in host2.name:
    #             return
    #         else:
    #             interface = host2.connectionsTo(host1)[0]
    #             interface_ip = interface.IP()
    #             Nfdc.registerRoute(host1, PREFIX, interface_ip)
    links = {"c1": ["i1", "i2"], "i1": ["p1"], "i2": ["p2"]}
    for first in links:
        for second in links[first]:
            host1 = ndn.net[first]
            host2 = ndn.net[second]
            interface = host2.connectionsTo(host1)[0]
            interface_ip = interface.IP()
            Nfdc.registerRoute(host1, PREFIX, interface_ip)
    interface = host2.connectionsTo(host1)[0]
    interface_ip = interface.IP()
    Nfdc.registerRoute(host1, PREFIX, interface_ip)

    # Run small thing before to ensure info caching, large afterwards?
    # print("Setup round")
    # getPopen(ndn.net["c1"], "ndn-traffic-client -c 5 cons_conf")
    # getPopen(ndn.net["p1"], "ndn-traffic-server -c 5 prod_conf")
    # # TODO: Traffic generator!
    # sleep(5)  # ?
    # nfds["i3"].stop()
    # tempshark = Tshark(ndn["c1"])
    # tempshark.start()

    # print("Round 1")
    # time1 = time()
    # getPopen(ndn.net["c1"], "ndn-traffic-client -c 20 cons_conf")
    # getPopen(ndn.net["p1"], "ndn-traffic-server -c 20 prod_conf")
    # # Wait on processes to close, end
    # time2 = time()
    # print("Time elapsed: {} s".format(time2 - time1))
    MiniNDNCLI(ndn.net)