コード例 #1
0
ファイル: topology.py プロジェクト: hsnlab/fero
  def __init__ (self, network=None, topo_desc=None):
    """
    Initialize Mininet implementation with proper attributes.
    Use network as the hided Mininet topology if it's given.

    :param topo_desc: static topology description e.g. the related NFFG
    :type topo_desc: :any:`NFFG`
    :param network: use this specific Mininet object for init (default: None)
    :type network: :class:`mininet.net.MininetWithControlNet`
    :return: None
    """
    log.debug("Init ESCAPENetworkBridge with topo description: %s" % topo_desc)
    if network is not None:
      self.__mininet = network
    else:
      log.warning(
        "Network implementation object is missing! Use Builder class instead "
        "of direct initialization. Creating bare Mininet object anyway...")
      self.__mininet = MininetWithControlNet()
    # Topology description which is emulated by the Mininet
    self.topo_desc = topo_desc
    # Duplicate static links for ensure undirected neighbour relationship
    if self.topo_desc is not None:
      back_links = [l.id for u, v, l in
                    self.topo_desc.network.edges_iter(data=True) if
                    l.backward is True]
      if len(back_links) == 0:
        log.debug("No backward link has been detected! Duplicate STATIC links "
                  "to ensure undirected relationship for mapping...")
      self.topo_desc.duplicate_static_links()
    # Need to clean after shutdown
    self._need_clean = None
    # There is no such flag in the Mininet class so using this
    self.started = False
    self.xterms = []
コード例 #2
0
ファイル: vnftest.py プロジェクト: whatever4711/escape
def netWithVNFs(netconf=False):
    "Create an empty network and add nodes to it."

    #ctl = InbandController( 'ctl', ip='192.168.123.1' )
    #ctl = InbandController( 'ctl', ip='127.0.0.1' )
    #net = MininetWithControlNet( )
    net = MininetWithControlNet(controller=Controller, autoSetMacs=True)
    #net = Mininet( controller=Controller )

    info('*** Adding controller\n')
    ctl = net.addController('c0', controller=RemoteController)

    #import pdb; pdb.set_trace();
    info('*** Adding hosts \n')
    h1 = net.addHost('h1')
    h2 = net.addHost('h2')

    info('*** Adding VNFs \n')

    if netconf:
        ee1 = net.addEE('ee1')
        ee1.setVNF(vnf_name='netconf')
        ee2 = net.addEE('ee2')
        ee2.setVNF(vnf_name='netconf')
        #[ exe1_sw, exe1_container ] = net.addManagedExe( 'exe1', nintf=5)
        #exe1_container.cmd = netconf.makeNetConfCmd()
    else:
        ee1 = net.addEE('ee1', cpu=0.1)
        #ee1.setVNF(vnf_name='fakeLoad', cpu='8', mem='5MB')
        ee1.setVNF(vnf_name='simpleForwarder', name=ee1.name)
        ee2 = net.addEE('ee2', cpu=0.1)
        ee2.setVNF(vnf_name='simpleObservationPoint', name=ee2.name)
        #ee2.setVNF(vnf_name='fakeLoad', cpu='8', mem='5MB')
        #ee2.setVNF(vnf_name='lookbusy',
        #    mem_util='5MB', cpu_util='8-20', cpu_mode='curve',
        #    cpu_curve_period='5m', cpu_curve_peak='2m' )

    info('*** Adding switches\n')
    s3 = net.addSwitch('s3')
    s4 = net.addSwitch('s4')

    info('*** Creating links\n')
    net.addLink(h1, s3)
    net.addLink(h2, s4)
    net.addLink(s3, s4)

    if netconf:
        net.addLink(exe1_sw, s3)
    else:
        net.addLink(ee1, s3)
        net.addLink(ee2, s4)

    info('*** Starting network\n')
    net.start()

    info('*** Running CLI\n')
    CLI(net)

    info('*** Stopping network')
    net.stop()
コード例 #3
0
 def _start_mininet(self, opts=None):
     if not opts:
         opts = {}
     self._info("***Starting mininet***")
     opts['controller'] = Controller
     opts['autoSetMacs'] = True
     self.net = MininetWithControlNet(**opts)
コード例 #4
0
ファイル: vnftest.py プロジェクト: tellesnobrega/escape
def netWithVNFs(netconf=False):
    "Create an empty network and add nodes and VNFs to it."

    net = MininetWithControlNet(controller=Controller, autoSetMacs=True)

    info('*** Adding controller\n')
    ctl = net.addController('c0', controller=RemoteController)

    info('*** Adding hosts \n')
    h1 = net.addHost('h1')
    h2 = net.addHost('h2')

    info('*** Adding VNFs \n')

    if netconf:
        ee1 = net.addEE('ee1')
        ee1.setVNF(vnf_name='netconf')
        ee2 = net.addEE('ee2')
        ee2.setVNF(vnf_name='netconf')
    else:
        ee1 = net.addEE('ee1', cpu=0.1)
        ee1.setVNF(vnf_name='simpleForwarder', name=ee1.name)
        ee2 = net.addEE('ee2', cpu=0.1)
        #ee2.setVNF(vnf_name='fakeload', name=ee2.name, cpu='8', mem='5MB')
        ee2.setVNF(vnf_name='simpleForwarder')

    info('*** Adding switches\n')
    s3 = net.addSwitch('s3')
    s4 = net.addSwitch('s4')

    info('*** Creating links\n')
    net.addLink(h1, s3)
    net.addLink(h2, s4)
    net.addLink(s3, s4)

    if netconf:
        net.addLink(exe1_sw, s3)
    else:
        net.addLink(ee1, s3)
        net.addLink(ee2, s4)

    info('*** Starting network\n')
    net.start()

    info('*** Running CLI\n')
    CLI(net)

    info('*** Stopping network')
    net.stop()
コード例 #5
0
    def __init__(self, net=None, opts=None, fallback=True, run_dry=True):
        """
    Initialize NetworkBuilder.

    If the topology definition is not found, an exception will be raised or
    an empty :class:`mininet.net.Mininet` topology will be created if
    ``run_dry`` is set.

    :param net: update given Mininet object instead of creating a new one
    :type net: :class:`mininet.net.Mininet`
    :param opts: update default options with the given opts
    :type opts: dict
    :param fallback: search for fallback topology (default: True)
    :type fallback: bool
    :param run_dry: do not raise an Exception and return with bare Mininet obj.
    :type run_dry: bool
    :return: None
    """
        self.opts = dict(self.default_opts)
        if opts is not None:
            self.opts.update(opts)
        self.fallback = fallback
        self.run_dry = run_dry
        if net is not None:
            if isinstance(net, Mininet):
                # Initial settings - Create new Mininet object if necessary
                self.mn = net
            else:
                raise TopologyBuilderException(
                    "Network object's type must be a derived class of Mininet!"
                )
        else:
            # self.mn = Mininet(**self.opts)
            try:
                self.mn = MininetWithControlNet(**self.opts)
            except KeyboardInterrupt:
                quit_with_error(
                    msg="Assembly of Mininet network was interrupted by user!",
                    logger=log)
        # Basically a wrapper for mn to offer helping functions
        self.mn_bridge = None
        # Cache of the topology description as an NFFG which is parsed during
        # initialization
        self.topo_desc = None
        self.__dpid_cntr = self.dpidBase
コード例 #6
0
ファイル: vnftest-iminds.py プロジェクト: whatever4711/escape
def netWithVNFs(netconf=False):
    "Create an empty network and add nodes to it."

    #ctl = InbandController( 'ctl', ip='192.168.123.1' )
    #ctl = InbandController( 'ctl', ip='127.0.0.1' )
    #net = MininetWithControlNet( )
    net = MininetWithControlNet(controller=Controller, autoSetMacs=True)
    #net = Mininet( controller=Controller )

    info('*** Adding controller\n')
    ctl = net.addController('c0', controller=RemoteController)

    #import pdb; pdb.set_trace();
    info('*** Adding hosts \n')
    h1 = net.addHost('h1')
    h2 = net.addHost('h2')

    info('*** Adding VNFs \n')

    if netconf:
        ee1 = net.addEE('ee1')
        ee1.setVNF(vnf_name='netconf')
        ee2 = net.addEE('ee2')
        ee2.setVNF(vnf_name='netconf')
        #[ exe1_sw, exe1_container ] = net.addManagedExe( 'exe1', nintf=5)
        #exe1_container.cmd = netconf.makeNetConfCmd()
    else:
        ee1 = net.addEE('ee1', cpu=0.1)
        #ee1.setVNF(vnf_name='fakeLoad', cpu='8', mem='5MB')
        ee1.setVNF(vnf_name='simpleForwarder',
                   device=ee1.name + '_eth1',
                   name=ee1.name)
        ee2 = net.addEE('ee2', cpu=0.1)

        #example for NAT with two ports connected to internal hosts (private addresses) and one port connected to the Internet (public address)
        device = [{
            'index': 0,
            'name': 'eth1',
            'ip1': '1.0.0.1',
            'ip2': '1.0.0.10'
        }, {
            'index': 1,
            'name': 'eth2',
            'ip1': '1.0.0.20',
            'ip2': '1.0.0.30'
        }]
        public = {'index': 2, 'name': 'eth2'}
        ee2.setVNF(vnf_name='nat', device=device, public=public)


#        ee2.setVNF(vnf_name='simpleObservationPoint', name=ee2.name)
#ee2.setVNF(vnf_name='fakeLoad', cpu='8', mem='5MB')
#ee2.setVNF(vnf_name='lookbusy',
#    mem_util='5MB', cpu_util='8-20', cpu_mode='curve',
#    cpu_curve_period='5m', cpu_curve_peak='2m' )

    info('*** Adding switches\n')
    s3 = net.addSwitch('s3')
    s4 = net.addSwitch('s4')

    info('*** Creating links\n')
    net.addLink(h1, s3)
    net.addLink(h2, s4)
    net.addLink(s3, s4)

    if netconf:
        net.addLink(exe1_sw, s3)
    else:
        net.addLink(ee1, s3)
        net.addLink(ee2, s4)

    info('*** Starting network\n')
    net.start()

    info('*** Running CLI\n')
    CLI(net)

    info('*** Stopping network')
    net.stop()