Exemplo n.º 1
0
 def stat_option(cls, stat=None, serverDetails=None):
     # each stat option we can do some specific functions
     if stat is None:
         stat = cls.statOptionsList
     if serverDetails is None:
         serverDetails = cls.serverOptionsList
     stat_choice = 'COLLECTD'
     test_name = cls.testHostName
     test_image = 'cordtest/nose'
     if stat_choice in stat:
         onos_ctrl = OnosCtrl('org.onosproject.cpman')
         status, _ = onos_ctrl.activate()
         if serverDetails is '':
             ## default Test Container is used to install CollectD
             pass
         elif serverDetails in 'NEW':
             test_image = 'cord-test/exserver'
             test_name = 'cord-collectd'
         else:
             pass
             # cls.connect_server(serverDetails)
             ## TO-DO for already up and running server, install collectd agent etc...
         cls.start_collectd_agent_in_server(name=test_name,
                                            image=test_image)
         for controller in cls.controllers:
             if not controller:
                 continue
             url_mem_stats = 'http://%s:8181/onos/cpman/controlmetrics/memory_metrics' % (
                 controller)
             url_cpu_stats = 'http://%s:8181/onos/cpman/controlmetrics/cpu_metrics' % (
                 controller)
             auth = ('karaf', 'karaf')
             cls.collectd_agent_metrics(controller, auth, url=url_cpu_stats)
             cls.collectd_agent_metrics(controller, auth, url=url_mem_stats)
     return
Exemplo n.º 2
0
 def disable_onos_apps(cls, stat=None, app=None):
     stat_choice = 'COLLECTD'
     if stat is None:
         stat = cls.statOptionsList
     if stat_choice in stat:
         onos_ctrl = OnosCtrl('org.onosproject.cpman')
         status, _ = onos_ctrl.deactivate()
Exemplo n.º 3
0
 def install_app_table(cls):
       ##Uninstall the existing app if any
       OnosCtrl.uninstall_app(cls.table_app)
       time.sleep(2)
       log.info('Installing the multi table app %s for subscriber test' %(cls.table_app_file))
       OnosCtrl.install_app(cls.table_app_file)
       time.sleep(3)
Exemplo n.º 4
0
 def vrouter_activate(cls, deactivate = False):
     app = 'org.onosproject.vrouter'
     onos_ctrl = OnosCtrl(app)
     if deactivate is True:
         onos_ctrl.deactivate()
     else:
         onos_ctrl.activate()
     time.sleep(3)
Exemplo n.º 5
0
 def iperf_network_test(df):
     cmd = 'iperf -c 172.17.0.2 -p 6653 -t 20 -P 1 -i 1'
     log.info('Test Controller by executing a iperf tool command on host = {}'.format(cmd))
     os.system(cmd)
     self.onos_ctrl = OnosCtrl(self.app)
     status, _ = self.onos_ctrl.activate()
     assert_equal(status, True)
     df.callback(0)
Exemplo n.º 6
0
 def tearDownClass(cls):
     '''Deactivate the olt apps and restart OVS back'''
     apps = cls.olt_apps + ( cls.table_app,)
     for app in apps:
         onos_ctrl = OnosCtrl(app)
         onos_ctrl.deactivate()
     cls.uninstall_app_table()
     cls.start_onos(network_cfg = {})
Exemplo n.º 7
0
 def setUp(self):
     ''' Activate the dhcp app'''
     super(dhcp_exchange, self).setUp()
     self.maxDiff = None  ##for assert_equal compare outputs on failure
     self.onos_ctrl = OnosCtrl(self.app)
     status, _ = self.onos_ctrl.activate()
     assert_equal(status, True)
     time.sleep(3)
Exemplo n.º 8
0
 def proxyarp_activate(cls, deactivate = False):
     app = 'org.onosproject.proxyarp'
     onos_ctrl = OnosCtrl(app)
     if deactivate is True:
         onos_ctrl.deactivate()
     else:
         onos_ctrl.activate()
     time.sleep(3)
Exemplo n.º 9
0
def __cord_test_ovs_flow_add(**kwargs):
    controller = get_controller()
    OnosCtrl.config_extraneous_flows(controller = controller)
    try:
        return rpc_server_instance(host = controller, port = CORD_TEST_PORT).ovs_flow_add(kwargs)
    except:
        pass

    try:
        return rpc_server_instance().ovs_flow_add(kwargs)
    except:
        pass

    return 'FAIL'
Exemplo n.º 10
0
 def __init__(self,
              ipv4Prefix='v4',
              srcIp='null',
              dstIp='null',
              ipProto='null',
              dstTpPort=0,
              action='null',
              ingress_iface=1,
              egress_iface=2,
              iface_num=0,
              iface_name='null',
              iface_count=0,
              iface_ip='null'):
     self.ipv4Prefix = ipv4Prefix
     self.srcIp = srcIp
     self.ingress_iface = ingress_iface
     self.egress_iface = egress_iface
     self.dstIp = dstIp
     self.ipProto = ipProto
     self.dstTpPort = dstTpPort
     self.action = action
     self.iface_count = iface_count
     self.iface_num = iface_num
     self.iface_name = iface_name
     self.iface_ip = iface_ip
     self.device_id = OnosCtrl.get_device_id()
Exemplo n.º 11
0
 def setUp(self):
     ''' Activate the dhcp app'''
     self.maxDiff = None ##for assert_equal compare outputs on failure
     self.onos_ctrl = OnosCtrl(self.app)
     status, _ = self.onos_ctrl.activate()
     assert_equal(status, True)
     time.sleep(3)
Exemplo n.º 12
0
 def __init__(self, iface = 'veth0', ssm_list = [], src_list = ['1.2.3.4'], delay = 2):
     self.iface = iface
     self.ssm_list += ssm_list
     self.src_list = src_list
     self.delay = delay
     self.onos_ctrl = OnosCtrl('org.onosproject.igmp')
     self.onos_ctrl.activate()
Exemplo n.º 13
0
 def install_cord_apps(cls, onos_ip = None):
     for app, version in cls.onos_cord_apps:
         app_file = '{}/{}-{}.oar'.format(cls.cord_apps_dir, app, version)
         ok, code = OnosCtrl.install_app(app_file, onos_ip = onos_ip)
         ##app already installed (conflicts)
         if code in [ 409 ]:
             ok = True
         print('ONOS app %s, version %s %s' %(app, version, 'installed' if ok else 'failed to install'))
         time.sleep(2)
Exemplo n.º 14
0
    def __init__(self,
                 iface='veth0',
                 ssm_list=[],
                 src_list=None,
                 delay=2,
                 controller=None):

        self.controller = controller
        self.iface = iface
        self.ssm_list += ssm_list
        if src_list is None:
            self.src_list = ['1.2.3.4']
        else:
            self.src_list = src_list
        self.delay = delay
        self.onos_ctrl = OnosCtrl('org.opencord.igmp',
                                  controller=self.controller)
        self.onos_ctrl.activate()
Exemplo n.º 15
0
 def setUpClass(cls):
     '''Load the OLT config and activate relevant apps'''
     did = cls.load_device_id()
     network_cfg = { "devices" : {
             "{}".format(did) : {
                   "basic" : {
                         "driver" : "pmc-olt"
                         }
                   }
             },
     }
     ## Restart ONOS with cpqd driver config for OVS
     cls.start_onos(network_cfg = network_cfg)
     cls.install_app_table()
     cls.olt = OltConfig(olt_conf_file = cls.olt_conf_file)
     OnosCtrl.cord_olt_config(cls.olt.olt_device_data())
     cls.port_map, cls.port_list = cls.olt.olt_port_map()
     cls.activate_apps(cls.apps + cls.olt_apps)
Exemplo n.º 16
0
 def load_device_id(cls):
     did = OnosCtrl.get_device_id()
     cls.device_id = did
     cls.device_dict = { "devices" : {
             "{}".format(did) : {
                 "basic" : {
                     "driver" : "softrouter"
                 }
             }
         },
     }
Exemplo n.º 17
0
 def load_device_id(cls):
     did = OnosCtrl.get_device_id()
     cls.device_id = did
     cls.vrouter_device_dict = { "devices" : {
             "{}".format(did) : {
                 "basic" : {
                     "driver" : "softrouter"
                 }
             }
         },
     }
Exemplo n.º 18
0
 def proxyarp_activate(cls, deactivate=False):
     app = 'org.onosproject.proxyarp'
     onos_ctrl = OnosCtrl(app)
     if deactivate is True:
         onos_ctrl.deactivate()
     else:
         onos_ctrl.activate()
     time.sleep(3)
Exemplo n.º 19
0
 def vrouter_activate(cls, deactivate=False):
     app = 'org.onosproject.vrouter'
     onos_ctrl = OnosCtrl(app)
     if deactivate is True:
         onos_ctrl.deactivate()
     else:
         onos_ctrl.activate()
     time.sleep(3)
Exemplo n.º 20
0
 def activate_apps(cls, deactivate = False):
     for app in cls.apps:
         onos_ctrl = OnosCtrl(app)
         if deactivate is False:
             onos_ctrl.activate()
         else:
             onos_ctrl.deactivate()
         time.sleep(2)
Exemplo n.º 21
0
 def stat_option(cls, stats=None, serverDetails=None):
     # each stats option we can do some specific functions
     if stats is None:
         stats = cls.stat_optionList
     if serverDetails is None:
         serverDetails = cls.serverOptionsList
     stats_choice = 'COLLECTD'
     test_name = cls.testHostName
     test_image = 'cordtest/nose'
     if stats_choice in stats:
         onos_ctrl = OnosCtrl('org.onosproject.cpman')
         status, _ = onos_ctrl.activate()
         if serverDetails is '':
             pass
         elif serverDetails in 'NEW':
             test_image = 'cord-test/exserver'
             test_name = 'cord-collectd'
         else:
             pass
             ## TO-DO for already up and running server, install collectd agent etc...
         cls.start_collectd_agent_in_server(name=test_name,
                                            image=test_image)
     return
Exemplo n.º 22
0
 def load_device_id(cls):
       '''Configure the device id'''
       did = OnosCtrl.get_device_id()
       #Set the default config
       cls.device_id = did
       cls.device_dict = { "devices" : {
                   "{}".format(did) : {
                         "basic" : {
                               "driver" : "pmc-olt"
                               }
                         }
                   },
             }
       return did
Exemplo n.º 23
0
    def test_initiating_pingall_from_mininet_with_onos_app_deactivation(self,switches=3):
        try:
	    topo = LinearTopo(switches)
            net = Mininet(topo=topo)
            net.start()
	    ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
            for switch in net.switches:
                switch.start( [ctrl] )
            response = net.pingAll()
            log.info('PingAll response before onos app \'org.onosproject.fwd\' deactivate is %s'%response)
            assert_equal(response, 0.0)
            OnosCtrl(self.app).deactivate()
            response = net.pingAll()
            log.info('PingAll response after onos app \'org.onosproject.fwd\' deactivate is %s'%response)
            assert_equal(response, 100.0)
	    net.stop()
        except Exception as Error:
            log.info('Got unexpected error %s while creating topology'%Error)
            Cleanup.cleanup()
            raise
	Cleanup.cleanup()
Exemplo n.º 24
0
    def getCredentials(cls):
        onos_cfg = OnosCtrl.get_config()
        if onos_cfg is None:
            return None
        if 'apps' in onos_cfg and \
           'org.opencord.vtn' in onos_cfg['apps'] and \
           'cordvtn' in onos_cfg['apps']['org.opencord.vtn'] and \
           'xos' in onos_cfg['apps']['org.opencord.vtn']['cordvtn']:
            xos_cfg = onos_cfg['apps']['org.opencord.vtn']['cordvtn']['xos']
            endpoint = xos_cfg['endpoint']
            user = xos_cfg['user']
            password = xos_cfg['password']
            xos_endpoints = endpoint.split(':')
            xos_host = xos_endpoints[0]
            xos_port = xos_endpoints[1]
            #log.info('xos_host: %s, port: %s, user: %s, password: %s' %(xos_host, xos_port, user, password))
            return dict(host=xos_host,
                        port=xos_port,
                        user=user,
                        password=password)

        return None
Exemplo n.º 25
0
 def iperf_network_test(df):
     cmd = 'iperf -c 172.17.0.2 -p 6653 -u -t 20 -P 1 -i 1'
     log.info('Test Controller by executing a iperf tool command on host = {}'.format(cmd))
     status = os.system(cmd)
     self.onos_ctrl = OnosCtrl(self.app)
     df.callback(0)
Exemplo n.º 26
0
class mininet_exchange(unittest.TestCase):
    app = 'org.onosproject.fwd'
    controller = os.getenv('ONOS_CONTROLLER_IP') or 'localhost'
    controller = controller.split(',')[0]

    @classmethod
    def setUpClass(cls):
	pass

    @classmethod
    def tearDownClass(cls):
	pwd = os.getcwd()
	log.info('teardown- current working dir is %s'%pwd)
	os.chdir('/root')
	cmds = ['rm -r mininet','apt-get remove mininet']
	for cmd in cmds:
            os.system(cmd)
        os.chdir(pwd)
        log.info('teardown- dir after removing mininet is %s'%os.getcwd())
        time.sleep(5)

    def setUp(self):
        self.onos_ctrl = OnosCtrl(self.app)
        self.onos_ctrl.activate()

    def tearDown(self):
        self.onos_ctrl = OnosCtrl(self.app)
        self.onos_ctrl.deactivate()

    def cliEnter(self, controller = None):
        retries = 0
        while retries < 30:
            self.cli = OnosCliDriver(controller = controller, connect = True)
            if self.cli.handle:
                break
            else:
                retries += 1
                time.sleep(2)

    def cliExit(self):
        self.cli.disconnect()

    def test_creation_of_topology(self):
        try:
            net = Mininet( topo=None, build=False)
            h1 = net.addHost( 'h1')
            h2 = net.addHost( 'h2' )
            h3 = net.addHost( 'h3' )
            s1 = net.addSwitch( 's1', dpid="0000000000000201")
            s2 = net.addSwitch( 's2', dpid="0000000000000202")
            s3 = net.addSwitch( 's3', dpid="0000000000000203")
            net.addLink(h1, s1, )
            net.addLink(h2, s2, )
            net.addLink(h3, s3, )
            net.addLink(s1, s2, )
            net.addLink(s2, s3, )
            #net.build()
            net.start()
            ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
	    s1.start( [ctrl] )
            s2.start( [ctrl] )
            s3.start( [ctrl] )
	    #CLI(net)
	    for switch in net.switches:
		log.info('dpid of switch is %s'%switch.dpid)
	    for host in net.hosts:
	   	log.info('host %s added with IP addres %s'%(host.name,host.IP()))
            net.stop()
	    log.info('Successfully created  mininet topology and connected to cluster controllers')
        except Exception as Error:
            log.info('Got error %s while creating topology'%Error)
            Cleanup.cleanup()
            raise
        Cleanup.cleanup()

    def test_creation_of_single_switch_topology(self,hosts=5):
        try:
            topo = SingleSwitchTopo(hosts)
            net = Mininet(topo=topo )
            net.start()
            log.info('Node connections are %s'%dumpNodeConnections(net.hosts))
      	    ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
	    for switch in net.switches:
                switch.start( [ctrl] )
            response = net.pingAll()
            log.info('Pingall response is %s'%response)
            assert_equal(response,0.0)
            net.stop()
        except Exception as Error:
            log.info('Got unexpected error %s while creating topology'%Error)
            Cleanup.cleanup()
            raise
        Cleanup.cleanup()

    def test_creation_of_linear_topology(self,switches=5):
        try:
            topo = LinearTopo(switches)
            net = Mininet(topo=topo)
            net.start()
            log.info('Node connections are %s'%dumpNodeConnections(net.hosts))
	    ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
            for switch in net.switches:
                switch.start( [ctrl] )
            response = net.pingAll()
            log.info('Pingall response is %s'%response)
            assert_equal(response,0.0)
	    #CLI(net)
            net.stop()
        except Exception as Error:
            log.info('Got unexpected error %s while creating minine topology'%Error)
            Cleanup.cleanup()
            raise
        Cleanup.cleanup()

    def test_creation_of_tree_topology(self):
        try:
            topo = TreeTopo(depth=2,fanout=2)
            net = Mininet(topo=topo)
            net.start()
            ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
            for switch in net.switches:
                switch.start( [ctrl] )
            response = net.pingAll()
            log.info('Pingall response is %s'%response)
            assert_equal(response,0.0)
            net.stop()
        except Exception as Error:
            log.info('Got unexpected error %s while creating topology'%Error)
            Cleanup.cleanup()
            raise
        Cleanup.cleanup()

    def test_executing_commands_from_mininet_host(self,switches=4):
        try:
            topo = LinearTopo(switches)
            net = Mininet(topo=topo)
            net.start()
	    ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
            for switch in net.switches:
                switch.start( [ctrl] )
            for host in net.hosts:
                result = host.cmd('ping -c 2', net.switches[0].IP())
                log.info('Result is %s'%result)
                res = result.find('icmp_seq')
                assert_not_equal(res, -1)
            net.stop()
        except Exception as Error:
            Cleanup.cleanup()
            log.info('Error while creating topology is %s'%Error)
            raise
        Cleanup.cleanup()

    def test_verifying_pingall_from_mininet(self,switches=5):
        try:
            topo = LinearTopo(switches)
            net = Mininet(topo=topo)
            net.start()
            ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
            for switch in net.switches:
                log.info('switch is %s'%switch  )
                switch.start([ctrl])
            response = net.pingAll()
            log.info('pingAll response is %s'%response)
            assert_equal(response,0.0)
        except Exception as Error:
            log.info('Got unexpected error %s while creating topology'%Error)
            Cleanup.cleanup()
            raise
        Cleanup.cleanup()

    def test_initiating_pingall_from_mininet_with_onos_app_deactivation(self,switches=3):
        try:
	    topo = LinearTopo(switches)
            net = Mininet(topo=topo)
            net.start()
	    ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
            for switch in net.switches:
                switch.start( [ctrl] )
            response = net.pingAll()
            log.info('PingAll response before onos app \'org.onosproject.fwd\' deactivate is %s'%response)
            assert_equal(response, 0.0)
            OnosCtrl(self.app).deactivate()
            response = net.pingAll()
            log.info('PingAll response after onos app \'org.onosproject.fwd\' deactivate is %s'%response)
            assert_equal(response, 100.0)
	    net.stop()
        except Exception as Error:
            log.info('Got unexpected error %s while creating topology'%Error)
            Cleanup.cleanup()
            raise
	Cleanup.cleanup()

    def test_verifying_mininet_hosts_in_onos_controller(self,switches=4):
        try:
	    topo = LinearTopo(switches)
            net = Mininet( topo=topo)
	    net.start()
	    ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
            for switch in net.switches:
                switch.start( [ctrl] )
            log.info('mininet all the devices IDs %s'%net.keys())
            log.info('mininet all the devices details %s'%net.values())
            log.info('mininet all the devices information %s'%net.items())
            response = net.pingAll()
            log.info('pingAll response is %s'%response)
            assert_equal(response, 0.0)
            self.cliEnter()
            hosts = json.loads(self.cli.hosts(jsonFormat = True))
            log.info('Discovered hosts: %s' %hosts)
            assert_equal(len(hosts),switches)
            self.cliExit()
        except Exception as Error:
            log.info('Got unexpected error %s while creating topology'%Error)
            Cleanup.cleanup()
            raise
        Cleanup.cleanup()

    def test_verifying_tcp_bandwidth_measure_between_mininet_hosts_using_iperf(self):
        try:
	    topo = TreeTopo(depth=2,fanout=2)
            net = Mininet( topo=topo, host=CPULimitedHost, link=TCLink, build=False)
            net.start()
	    ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
            for switch in net.switches:
                switch.start( [ctrl] )
            response = net.pingAll()
            log.info('PingAll response is %s'%response)
            bandwidth = net.iperf()
            log.info('TCP Bandwidth between hosts measured using iperf is %s'%bandwidth)
            assert_equal(len(bandwidth),2)
            net.stop()
        except Exception as Error:
            log.info('Got unexpected error %s while creating topology'%Error)
            Cleanup.cleanup()
            raise
        Cleanup.cleanup()

    def test_verifying_udp_bandwidth_measure_between_mininet_hosts_using_iperf(self):
        try:
            topo = TreeTopo(depth=2,fanout=2)
            net = Mininet( topo=topo, host=CPULimitedHost, link=TCLink, build=False)
            net.start()
            ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
            for switch in net.switches:
                switch.start( [ctrl] )
            response = net.pingAll()
            log.info('pingAll response is %s'%response)
            bandwidth = net.iperf(l4Type = 'UDP')
            log.info('UDP Bandwidth between hosts measured using iperf is %s'%bandwidth)
            assert_equal(len(bandwidth),3)
            net.stop()
        except Exception as Error:
            log.info('Got unexpected error %s while creating topology'%Error)
            Cleanup.cleanup()
            raise
        Cleanup.cleanup()

    def test_verifying_tcp_bandwidth_between_mininet_hosts_using_iperf_with_one_host_removed(self,switches=3):
        try:
            topo = LinearTopo(switches)
            net = Mininet(topo=topo)
            net.start()
            ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
            for switch in net.switches:
                switch.start( [ctrl] )
            response = net.pingAll()
            iperf = net.iperf(l4Type='TCP')
            log.info('Iperf response before host removed is %s'%iperf)
            assert_equal(len(iperf),2)
	    net.delNode(net.hosts[2])
            iperf = net.iperf(l4Type='TCP')
            log.info('Iperf response after host removed is %s'%iperf)
	    assert_equal(len(iperf),2)
            net.stop()
        except Exception as Error:
            log.info('Got unexpected error %s while creating topology'%Error)
            Cleanup.cleanup()
            raise
        Cleanup.cleanup()

    def test_verifying_udp_bandwidth_between_mininet_hosts_using_iperf_with_one_host_removed(self,switches=3):
        try:
            topo = LinearTopo(switches)
            net = Mininet(topo=topo)
            net.start()
            ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
            for switch in net.switches:
                switch.start( [ctrl] )
            response = net.pingAll()
            iperf = net.iperf(l4Type='UDP')
            log.info('Iperf response before host removed is %s'%iperf)
            assert_equal(len(iperf),3)
            net.delNode(net.hosts[2])
            iperf = net.iperf(l4Type='UDP')
            log.info('Iperf response after host removed is %s'%iperf)
	    assert_equal(len(iperf),3)
            net.stop()
        except Exception as Error:
            log.info('Got unexpected error %s while creating topology'%Error)
            Cleanup.cleanup()
            raise
        Cleanup.cleanup()

    def test_hosts_assigned_with_non_default_ip_address(self):
        try:
            net = Mininet( topo=None, controller=RemoteController, host=CPULimitedHost, link=TCLink, build=False)
            h1 = net.addHost( 'h1', ip='192.168.10.1/24' )
            h2 = net.addHost( 'h2', ip='192.168.10.10/24' )
            s1 = net.addSwitch( 's1')
            s2 = net.addSwitch( 's2')
            net.addLink(h1, s1, )
            net.addLink(h2, s2, )
            net.addLink(s1, s2, )
	    ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
            for switch in net.switches:
                switch.start( [ctrl] )
            net.start()
            assert_equal(net.hosts[0].IP(),'192.168.10.1')
            assert_equal(net.hosts[1].IP(),'192.168.10.10')
            response = net.pingAll()
            log.info('PingAll response is %s'%response)
            assert_equal(response,0.0)
        except Exception as Error:
            log.info('Got unexpected error %s while creating topology'%Error)
            Cleanup.cleanup()
            raise
        Cleanup.cleanup()

    def test_hosts_assigned_with_non_default_ip_address_in_different_subnets(self):
        try:
            net = Mininet( topo=None, controller=RemoteController, host=CPULimitedHost, link=TCLink, build=False)
            h1 = net.addHost( 'h1', ip='192.168.10.10/24' )
            h2 = net.addHost( 'h2', ip='192.168.20.10/24' )
            s1 = net.addSwitch( 's1')
            s2 = net.addSwitch( 's2')
            net.addLink(h1, s1, )
            net.addLink(h2, s2, )
            net.addLink(s1, s2, )
            net.start()
	    ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
            for switch in net.switches:
                switch.start( [ctrl] )
            assert_equal(net.hosts[0].IP(),'192.168.10.10')
            assert_equal(net.hosts[1].IP(),'192.168.20.10')
            response = net.pingAll()
            log.info('pingAll response is %s'%response)
            assert_equal(response,100.0)
        except Exception as Error:
            log.info('Got unexpected error %s while creating topology'%Error)
            Cleanup.cleanup()
            raise
        Cleanup.cleanup()

    def test_verifying_pingall_with_connection_remove_between_switches(self,switches=4):
        try:
	    topo = LinearTopo(switches)
            net = Mininet(topo=topo)
	    #net.build()
            net.start()
	    ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
            for switch in net.switches:
                switch.start( [ctrl] )
            response = net.pingAll()
            log.info('Pingall response before link delete is %s'%response)
            assert_equal(response,0.0)
            log.info('Deleting link between switches s1 and s2')
            net.delLinkBetween(net.switches[0], net.switches[1], )
            response = net.pingAll()
            log.info('Pingall response after the link delete is is %s'%response)
            assert_not_equal(response,0.0)
            net.stop()
        except Exception as Error:
            log.info('Got error %s while creating topology'%Error)
            Cleanup.cleanup()
            raise
        Cleanup.cleanup()

    def test_verifying_pingall_with_removing_one_mininet_host(self,switches=3):
        try:
	    topo = LinearTopo(switches)
            net = Mininet(topo=topo)
	    #net.build()
            net.start()
            ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
            for switch in net.switches:
                switch.start( [ctrl] )
            response = net.pingAll()
            log.info('Pingall response before host delete is %s'%response)
            assert_equal(response,0.0)
            log.info('removing host h2')
            net.delNode(net.hosts[1])
            response = net.pingAll()
            log.info('Pingall response after host delete is %s'%response)
            assert_equal(response,0)
            net.stop()
        except Exception as Error:
            log.info('Got error %s while creating topology'%Error)
            Cleanup.cleanup()
            raise
        Cleanup.cleanup()

    def test_verifying_pingall_with_removing_one_mininet_switch(self,switches=3):
        try:
	    topo = LinearTopo(switches)
            net = Mininet(topo=topo)
	    #net.build()
            net.start()
	    ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
            for switch in net.switches:
                switch.start( [ctrl] )
            response = net.pingAll()
            log.info('Pingall response before switch delete is %s'%response)
            assert_equal(response,0.0)
            log.info('Deleting switch s2')
            net.delNode(net.switches[1])
            response = net.pingAll()
            log.info('Pingall response after switch delete is %s'%response)
            assert_not_equal(response,0.0)
            net.stop()
        except Exception as Error:
            log.info('Got error %s while creating topology'%Error)
            Cleanup.cleanup()
            raise
        Cleanup.cleanup()

    def test_verifying_mininet_switch_status_in_onos_controller(self,switches=4):
        try:
	    topo = LinearTopo(switches)
            net = Mininet(topo=topo, build=False)
            net.start()
            ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
            for switch in net.switches:
                switch.start( [ctrl] )
            response = net.pingAll()
            log.info('Pingall response is %s'%response)
            assert_equal(response,0.0)
            self.cliEnter()
            devices = json.loads(self.cli.devices(jsonFormat = True))
	    count = 0
	    switch_ids = []
	    for switch in net.switches:
                dvcid = 'of:'+switch.dpid
                switch_ids.append(dvcid)
	    for device in devices:
	        if str(device['id']) in switch_ids:
	            assert_equal(str(device['available']), 'True')
		    count += 1
	    assert_equal(count,switches)
            self.cliExit()
            net.stop()
        except Exception as Error:
            log.info('Got error %s while creating topology'%Error)
            Cleanup.cleanup()
            raise
        Cleanup.cleanup()

    def test_verify_host_status_in_onos_controller_with_removing_one_mininet_host(self,switches=5):
        try:
	    topo = LinearTopo(switches)
            net = Mininet( topo=topo, build=False)
            net.start()
            ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
            for switch in net.switches:
                switch.start( [ctrl] )
            response = net.pingAll()
            log.info('pingall response is %s'%response)
            assert_equal(response,0.0)
            self.cliEnter()
            hosts = json.loads(self.cli.hosts(jsonFormat = True))
	    log.info('Discovered Hosts are %s'%hosts)
            assert_equal(len(hosts),switches)
            log.info('removing host h2')
            net.delNode(net.hosts[0])
            hosts = json.loads(self.cli.hosts(jsonFormat = True))
            assert_equal(len(hosts),switches-1)
            self.cliExit()
            net.stop()
        except Exception as Error:
            log.info('Got error %s while creating topology'%Error)
            Cleanup.cleanup()
            raise
        Cleanup.cleanup()

    def test_verifying_pushing_mac_flows_from_onos_controller_to_mininet_switches(self,switches=3):
        try:
            topo = LinearTopo(switches)
            net = Mininet( topo=topo)
            net.start()
            egress_mac = RandMAC()._fix()
            ingress_mac = RandMAC()._fix()
            egress = 1
            ingress = 2
	    ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
            for switch in net.switches:
                switch.start( [ctrl] )
            response = net.pingAll()
            log.info('pingAll response is %s'%response)
            self.cliEnter()
            devices = json.loads(self.cli.devices(jsonFormat = True))
            for switch in net.switches:
		dvcid = 'of:'+switch.dpid
                flow = OnosFlowCtrl(deviceId = dvcid,
                                        egressPort = egress,
                                        ingressPort = ingress,
                                        ethSrc = ingress_mac,
                                        ethDst = egress_mac)
                result = flow.addFlow()
                assert_equal(result, True)
	    self.cliExit()
            net.stop()
        except Exception as Error:
            log.info('Got unexpected error %s while creating topology'%Error)
            Cleanup.cleanup()
            raise
        Cleanup.cleanup()

    def test_verifying_pushing_ipv4_flows_from_onos_controller_to_mininet_switches(self,switches=5):
        try:
            topo = LinearTopo(switches)
            net = Mininet( topo=topo)
            net.start()
            ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
            for switch in net.switches:
                switch.start( [ctrl] )
            egress = 1
            ingress = 2
            egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1' }
            ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1' }
            response = net.pingAll()
            log.info('pingAll response is %s'%response)
            for switch in net.switches:
		dvcid = 'of:'+switch.dpid
                flow = OnosFlowCtrl(deviceId = dvcid,
                                    egressPort = egress,
                                    ingressPort = ingress,
                                    ethType = '0x0800',
				    ipSrc = ('IPV4_SRC', ingress_map['ip']+'/32'),
                                    ipDst = ('IPV4_DST', egress_map['ip']+'/32')
                                    )
                result = flow.addFlow()
                assert_equal(result, True)
            net.stop()
        except Exception as Error:
            log.info('Got unexpected error %s while creating topology'%Error)
            Cleanup.cleanup()
            raise
        Cleanup.cleanup()

    def test_verifying_pushing_ipv6_flows_from_onos_controller_to_mininet_switches(self,switches=5):
	try:
	    topo = LinearTopo(switches)
	    net = Mininet( topo=topo)
            net.start()
            ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
            for switch in net.switches:
                switch.start( [ctrl] )
            egress = 1
            ingress = 2
            egress_map = { 'ether': '00:00:00:00:00:03', 'ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1001' }
            ingress_map = { 'ether': '00:00:00:00:00:04', 'ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1002' }
	    response = net.pingAll()
            log.info('pingAll response is %s'%response)
            for switch in net.switches:
		dvcid = 'of:'+switch.dpid
                flow = OnosFlowCtrl(deviceId = dvcid,
                                    egressPort = egress,
                                    ingressPort = ingress,
                                    ethType = '0x86dd',
                            	    ipSrc = ('IPV6_SRC', ingress_map['ipv6'] + '/48'),
                            	    ipDst = ('IPV6_DST', egress_map['ipv6'] + '/48')
                                    )
                result = flow.addFlow()
                assert_equal(result, True)
            net.stop()
   	except Exception as Error:
            log.info('Got unexpected error %s while creating topology'%Error)
            Cleanup.cleanup()
            raise
        Cleanup.cleanup()

    def test_topology_created_with_50_switches_in_onos_controller(self,switches=50):
	try:
	    topo = LinearTopo(switches)
	    net = Mininet(topo=topo)
	    net.start()
	    ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
	    for switch in net.switches:
                switch.start([ctrl])
	    time.sleep(5)
	    self.cliEnter()
            devices = json.loads(self.cli.devices(jsonFormat = True))
	    device_list = []
	    count = 0
	    for device in devices:
		device_list.append(str(device['id']))
	    log.info('device list is %s'%device_list)
	    for switch in net.switches:
                switch_id = 'of:'+switch.dpid
		if switch_id in device_list:
		    count += 1
	    assert_equal(count,switches)
	    self.cliExit()
	    net.stop()
	except Exception as Error:
	    log.info('Got unexpected error %s while creating topology'%Error)
            Cleanup.cleanup()
            raise
	Cleanup.cleanup()

    def test_topology_created_with_200_switches_in_onos_controller(self,switches=200):
        try:
            topo = LinearTopo(switches)
            net = Mininet(topo=topo)
            net.start()
            ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
            for switch in net.switches:
                log.info('switch is %s'%switch  )
                switch.start([ctrl])
	    time.sleep(10)
	    self.cliEnter()
            devices = json.loads(self.cli.devices(jsonFormat = True))
            device_list = []
            count = 0
	    for device in devices:
                device_list.append(str(device['id']))
            log.info('device list is %s'%device_list)
            for switch in net.switches:
                switch_id = 'of:'+switch.dpid
                if switch_id in device_list:
                    count += 1
            assert_equal(count,switches)
	    self.cliExit()
	    net.stop()
        except Exception as Error:
            log.info('Got unexpected error %s while creating topology'%Error)
            Cleanup.cleanup()
            raise
        Cleanup.cleanup()

    def test_verifying_nodes_removed_in_mininet_status_in_onos_controller(self,switches=50, delete=20):
        try:
            topo = LinearTopo(switches)
            net = Mininet(topo=topo)
            net.start()
            o1_ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
            for switch in net.switches:
                log.info('switch is %s'%switch)
                switch.start([o1_ctrl])
	    time.sleep(5)
	    self.cliEnter()
            devices = json.loads(self.cli.devices(jsonFormat = True))
            device_list = []
            count = 0
            for device in devices:
                device_list.append(str(device['id']))
            log.info('device list is %s'%device_list)
            for switch in net.switches:
                switch_id = 'of:'+switch.dpid
                if switch_id in device_list:
                    count += 1
            assert_equal(count,switches)
	    count = 0
	    dltd_list = []
	    for switch in net.switches:
                log.info('Switch is %s'%switch)
	        dltd_list.append('of:'+switch.dpid)
                net.delNode(switch)
                count += 1
                if count == delete:
                    break
	    log.info('deleted switch dpid\'s %s'%dltd_list)
	    count = 0
	    devices = json.loads(self.cli.devices(jsonFormat = True))
	    for device in devices:
		if str(device['id']) in dltd_list:
		    assert_equal(str(device['available']), 'False')
		    count += 1
	    assert_equal(count,delete)
	    self.cliExit()
	    net.stop()
        except Exception as Error:
            log.info('Got unexpected error %s while creating topology'%Error)
            Cleanup.cleanup()
            raise
        Cleanup.cleanup()
Exemplo n.º 27
0
class iperf_exchange(unittest.TestCase):

    switch_script = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../setup', 'of-bridge.sh')
    switch = 'br-int'
    ctlr_ip = os.getenv('ONOS_CONTROLLER_IP', 'localhost')
    ctlr_port = '6653'
    IPERF_TIMEOUT = 360
    app = 'org.onosproject.dhcp'

    @classmethod
    def setUpClass(cls):
        #cls.stop_switch()
        #cls.install_app()
        cmd = "apt-get install iperf"
        os.system(cmd)
        time.sleep(40)

    @classmethod
    def tearDownClass(cls):pass
        #cls.onos_ctrl.deactivate()

    @classmethod
    def install_app(cls):
        OnosCtrl.uninstall_app(cls.igmp_app)
        time.sleep(2)
        OnosCtrl.install_app(cls.igmp_app_file)
        time.sleep(3)

    def cliEnter(self):
        retries = 0
        while retries < 3:
            self.cli = OnosCliDriver(connect = True)
            if self.cli.handle:
                break
            else:
                retries += 1
                time.sleep(2)

    def cliExit(self):
        self.cli.disconnect()

    @classmethod
    def iperf_tool_cmd_execution(cls,cmd = " "):
        log.info('Test Controller by executing a iperf tool command on host = {}'.format(cmd))

        try:
#           status = os.system(cmd)
            status = subprocess.Popen(cmd, shell=True)
            time.sleep(90)
            pid = status.pid
            log.info('Subprocess status = {}'.format(status))
            log.info('Subprocess task id on host = {}'.format(pid))
            status.terminate()
        except Exception:
            status.terminate()
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanup()
            main.exit()

    @deferred(IPERF_TIMEOUT)
    def test_tcp_using_iperf(self):
        df = defer.Deferred()
        def iperf_network_test(df):
            cmd = 'iperf -c 172.17.0.2 -p 6653 -t 20 -P 1 -i 1'
            log.info('Test Controller by executing a iperf tool command on host = {}'.format(cmd))
            os.system(cmd)
            self.onos_ctrl = OnosCtrl(self.app)
            status, _ = self.onos_ctrl.activate()
            assert_equal(status, True)
            df.callback(0)
        reactor.callLater(0, iperf_network_test, df)
        return df

    @deferred(IPERF_TIMEOUT)
    def test_udp_using_iperf(self):
        df = defer.Deferred()
        def iperf_network_test(df):
            cmd = 'iperf -c 172.17.0.2 -p 6653 -u -t 20 -P 1 -i 1'
            log.info('Test Controller by executing a iperf tool command on host = {}'.format(cmd))
            status = os.system(cmd)
            self.onos_ctrl = OnosCtrl(self.app)
            df.callback(0)
        reactor.callLater(0, iperf_network_test, df)
        return df

    @deferred(IPERF_TIMEOUT)
    def test_tcp_window_of_40k_using_iperf(self):
        df = defer.Deferred()
        def iperf_network_test(df):
            cmd = 'iperf -c 172.17.0.2 -p 6653 -t 20 -P 1 -i 1 -w 40k'
            log.info('Test Controller by executing a iperf tool command on host = {}'.format(cmd))
            status = os.system(cmd)
            df.callback(0)
        reactor.callLater(0, iperf_network_test, df)
        return df


    @deferred(IPERF_TIMEOUT)
    def test_tcp_window_of_120k_using_iperf(self):
        df = defer.Deferred()
        def iperf_network_test(df):
            cmd = 'iperf -c 172.17.0.2 -p 6653 -t 20 -P 1 -i 1 -w 120k'
            log.info('Test Controller by executing a iperf tool command on host = {}'.format(cmd))
            status = os.system(cmd)
            df.callback(0)
        reactor.callLater(0, iperf_network_test, df)
        return df


    @deferred(IPERF_TIMEOUT)
    def test_tcp_window_of_520k_using_iperf(self):
        df = defer.Deferred()
        def iperf_network_test(df):
            cmd = 'iperf -c 172.17.0.2 -p 6653 -t 20 -P 1 -i 1 -w 520k'
            log.info('Test Controller by executing a iperf tool command on host = {}'.format(cmd))
            status = os.system(cmd)
            df.callback(0)
        reactor.callLater(0, iperf_network_test, df)
        return df

    @deferred(IPERF_TIMEOUT)
    def test_multiple_tcp_sessions_using_iperf(self):
        df = defer.Deferred()
        def iperf_network_test(df):
            cmd = 'iperf -c 172.17.0.2 -p 6653 -t 5 -P 2 -i 1'
            self.iperf_tool_cmd_execution(cmd = cmd)
            df.callback(0)
        reactor.callLater(0, iperf_network_test, df)
        return df

    @deferred(IPERF_TIMEOUT)
    def test_multiple_udp_sessions_using_iperf(self):
        df = defer.Deferred()
        def iperf_network_test(df):
            cmd = 'iperf -c 172.17.0.2 -p 6653 -u -t 5 -P 2 -i 1'
            log.info('Test Controller by executing a iperf tool command on host = {}'.format(cmd))
            status = os.system(cmd)
            df.callback(0)
        reactor.callLater(0, iperf_network_test, df)
        return df


    @deferred(IPERF_TIMEOUT)
    def test_tcp_mss_with_90Bytes_using_iperf(self):
        df = defer.Deferred()
        def iperf_network_test(df):
            cmd = 'iperf -c 172.17.0.2 -p 6653 -t 20 -P 1 -i 1 -m -M 90'
            log.info('Test Controller by executing a iperf tool command on host = {}'.format(cmd))
            status = os.system(cmd)
            df.callback(0)
        reactor.callLater(0, iperf_network_test, df)
        return df

    @deferred(IPERF_TIMEOUT)
    def test_tcp_mss_with_1490Bytes_using_iperf(self):
        df = defer.Deferred()
        def iperf_network_test(df):
            cmd = 'iperf -c 172.17.0.2 -p 6653 -t 20 -P 1 -i 1 -m -M 1490'
            log.info('Test Controller by executing a iperf tool command on host = {}'.format(cmd))
            status = os.system(cmd)
            df.callback(0)
        reactor.callLater(0, iperf_network_test, df)
        return df

    @deferred(IPERF_TIMEOUT)
    def test_tcp_mss_with_9000Bytes_for_max_throughput_using_iperf(self):
        df = defer.Deferred()
        def iperf_network_test(df):
            cmd = 'iperf -c 172.17.0.2 -p 6653 -t 20 -P 1 -i 1 -m -M 9000'
            log.info('Test Controller by executing a iperf tool command on host = {}'.format(cmd))
            status = os.system(cmd)
            df.callback(0)
        reactor.callLater(0, iperf_network_test, df)
        return df
Exemplo n.º 28
0
 def tearDown(self):
     self.onos_ctrl = OnosCtrl(self.app)
     self.onos_ctrl.deactivate()
Exemplo n.º 29
0
 def setUp(self):
     self.onos_ctrl = OnosCtrl(self.app)
     self.onos_ctrl.activate()
Exemplo n.º 30
0
 def activate_apps(cls, apps):
       for app in apps:
             onos_ctrl = OnosCtrl(app)
             status, _ = onos_ctrl.activate()
             assert_equal(status, True)
             time.sleep(2)
Exemplo n.º 31
0
    def host_config_load(cls, host_config = None):
	for host in host_config:
	    status, code = OnosCtrl.host_config(host)
	    if status is False:
                log.info('JSON request returned status %d' %code)
                assert_equal(status, True)
Exemplo n.º 32
0
class dhcp_exchange(unittest.TestCase):

    dhcp_server_config = {
        "ip": "10.1.11.50",
        "mac": "ca:fe:ca:fe:ca:fe",
        "subnet": "255.255.252.0",
        "broadcast": "10.1.11.255",
        "router": "10.1.8.1",
        "domain": "8.8.8.8",
        "ttl": "63",
        "delay": "2",
        "startip": "10.1.11.51",
        "endip": "10.1.11.100"
    }

    app = 'org.onosproject.dhcp'

    ip_count = 0
    failure_count = 0
    start_time = 0
    diff = 0

    transaction_count = 0
    transactions = 0
    running_time = 0
    total_success = 0
    total_failure = 0

    @classmethod
    def setUpClass(cls):
        cls.olt = OltConfig()
        cls.port_map, _ = cls.olt.olt_port_map()
        if not cls.port_map:
            cls.port_map = g_subscriber_port_map
        cls.iface = cls.port_map[1]

    def setUp(self):
        ''' Activate the dhcp app'''
        self.maxDiff = None ##for assert_equal compare outputs on failure
        self.onos_ctrl = OnosCtrl(self.app)
        status, _ = self.onos_ctrl.activate()
        assert_equal(status, True)
        time.sleep(3)

    def teardown(self):
        '''Deactivate the dhcp app'''
        self.onos_ctrl.deactivate()

    def onos_load_config(self, config):
        status, code = OnosCtrl.config(config)
        if status is False:
            log.info('JSON request returned status %d' %code)
            assert_equal(status, True)
        time.sleep(3)

    def onos_dhcp_table_load(self, config = None):
          dhcp_dict = {'apps' : { 'org.onosproject.dhcp' : { 'dhcp' : copy.copy(self.dhcp_server_config) } } }
          dhcp_config = dhcp_dict['apps']['org.onosproject.dhcp']['dhcp']
          if config:
              for k in config.keys():
                  if dhcp_config.has_key(k):
                      dhcp_config[k] = config[k]
          self.onos_load_config(dhcp_dict)

    def send_recv(self, mac = None, update_seed = False, validate = True):
        cip, sip = self.dhcp.discover(mac = mac, update_seed = update_seed)
        if validate:
            assert_not_equal(cip, None)
            assert_not_equal(sip, None)
            log.info('Got dhcp client IP %s from server %s for mac %s' %
                     (cip, sip, self.dhcp.get_mac(cip)[0]))
        return cip,sip

    def stats(self,success_rate = False, only_discover = False):

	self.ip_count = 0
	self.failure_count = 0
	self.start_time = 0
	self.diff = 0
	self.transaction_count = 0
	config = {'startip':'182.17.0.3', 'endip':'182.17.0.180',
                  'ip':'182.17.0.2', 'mac': "ca:fe:c3:fe:ca:fe",
                  'subnet': '255.255.255.0', 'broadcast':'182.17.0.255', 'router':'182.17.0.1'}
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = self.iface)
	self.start_time = time.time()

	while self.diff <= 60:
	    if only_discover:
		cip, sip, mac, _ = self.dhcp.only_discover(multiple = True)
                log.info('Got dhcp client IP %s from server %s for mac %s' %
                          (cip, sip, mac))
            else:
                cip, sip = self.send_recv(update_seed = True, validate = False)

	    if cip:
	    	self.ip_count +=1
	    elif cip == None:
		self.failure_count += 1
                log.info('Failed to get ip')
		if success_rate and self.ip_count > 0:
		   break
	    self.diff = round(time.time() - self.start_time, 0)


	self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)

    	self.transactions += (self.ip_count+self.failure_count)
	self.running_time += self.diff
        self.total_success += self.ip_count
	self.total_failure += self.failure_count

    def test_dhcp_1request(self):
        config = {'startip':'10.10.10.20', 'endip':'10.10.10.69',
                  'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe",
                  'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'}
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = self.iface)
        self.send_recv()

    def test_dhcp_Nrequest(self):
        config = {'startip':'192.168.1.20', 'endip':'192.168.1.69',
                  'ip':'192.168.1.2', 'mac': "ca:fe:ca:fe:cc:fe",
                  'subnet': '255.255.255.0', 'broadcast':'192.168.1.255', 'router': '192.168.1.1'}
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip = '192.169.1.1', iface = self.iface)
        ip_map = {}
        for i in range(10):
            cip, sip = self.send_recv(update_seed = True)
            if ip_map.has_key(cip):
                log.info('IP %s given out multiple times' %cip)
                assert_equal(False, ip_map.has_key(cip))
            ip_map[cip] = sip

    def test_dhcp_1release(self):
        config = {'startip':'10.10.100.20', 'endip':'10.10.100.21',
                  'ip':'10.10.100.2', 'mac': "ca:fe:ca:fe:8a:fe",
                  'subnet': '255.255.255.0', 'broadcast':'10.10.100.255', 'router':'10.10.100.1'}
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip = '10.10.100.10', iface = self.iface)
        cip, sip = self.send_recv()
        log.info('Releasing ip %s to server %s' %(cip, sip))
        assert_equal(self.dhcp.release(cip), True)
        log.info('Triggering DHCP discover again after release')
        cip2, sip2 = self.send_recv(update_seed = True)
        log.info('Verifying released IP was given back on rediscover')
        assert_equal(cip, cip2)
        log.info('Test done. Releasing ip %s to server %s' %(cip2, sip2))
        assert_equal(self.dhcp.release(cip2), True)

    def test_dhcp_Nrelease(self):
        config = {'startip':'192.170.1.20', 'endip':'192.170.1.30',
                  'ip':'192.170.1.2', 'mac': "ca:fe:ca:fe:9a:fe",
                  'subnet': '255.255.255.0', 'broadcast':'192.170.1.255', 'router': '192.170.1.1'}
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = self.iface)
        ip_map = {}
        for i in range(10):
            cip, sip = self.send_recv(update_seed = True)
            if ip_map.has_key(cip):
                log.info('IP %s given out multiple times' %cip)
                assert_equal(False, ip_map.has_key(cip))
            ip_map[cip] = sip

        for ip in ip_map.keys():
            log.info('Releasing IP %s' %ip)
            assert_equal(self.dhcp.release(ip), True)

        ip_map2 = {}
        log.info('Triggering DHCP discover again after release')
        for i in range(len(ip_map.keys())):
            cip, sip = self.send_recv(update_seed = True)
            ip_map2[cip] = sip

        log.info('Verifying released IPs were given back on rediscover')
        if ip_map != ip_map2:
            log.info('Map before release %s' %ip_map)
            log.info('Map after release %s' %ip_map2)
        assert_equal(ip_map, ip_map2)


    def test_dhcp_starvation(self):
        config = {'startip':'193.170.1.20', 'endip':'193.170.1.69',
                  'ip':'193.170.1.2', 'mac': "ca:fe:c2:fe:cc:fe",
                  'subnet': '255.255.255.0', 'broadcast':'192.168.1.255', 'router': '192.168.1.1'}
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip = '192.169.1.1', iface = self.iface)
        ip_map = {}
        for i in range(10):
            cip, sip = self.send_recv(update_seed = True)
            if ip_map.has_key(cip):
                log.info('IP %s given out multiple times' %cip)
                assert_equal(False, ip_map.has_key(cip))
            ip_map[cip] = sip


    def test_dhcp_starvation(self):
        config = {'startip':'182.17.0.20', 'endip':'182.17.0.69',
                  'ip':'182.17.0.2', 'mac': "ca:fe:c3:fe:ca:fe",
                  'subnet': '255.255.255.0', 'broadcast':'182.17.0.255', 'router':'182.17.0.1'}
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = self.iface)
        log.info('Verifying 1 ')
        for x in xrange(50):
            mac = RandMAC()._fix()
            self.send_recv(mac = mac)
        log.info('Verifying 2 ')
        cip, sip = self.send_recv(update_seed = True, validate = False)
        assert_equal(cip, None)
        assert_equal(sip, None)


    def test_dhcp_same_client_multiple_discover(self):
	config = {'startip':'10.10.10.20', 'endip':'10.10.10.69',
                 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe",
                 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'}
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = self.iface)
	cip, sip, mac, _ = self.dhcp.only_discover()
	log.info('Got dhcp client IP %s from server %s for mac %s . Not going to send DHCPREQUEST.' %
		  (cip, sip, mac) )
	log.info('Triggering DHCP discover again.')
	new_cip, new_sip, new_mac, _ = self.dhcp.only_discover()
	if cip == new_cip:
		log.info('Got same ip for 2nd DHCP discover for client IP %s from server %s for mac %s. Triggering DHCP Request. '
			  % (new_cip, new_sip, new_mac) )
	elif cip != new_cip:
		log.info('Ip after 1st discover %s' %cip)
                log.info('Map after 2nd discover %s' %new_cip)
		assert_equal(cip, new_cip)


    def test_dhcp_same_client_multiple_request(self):
	config = {'startip':'10.10.10.20', 'endip':'10.10.10.69',
                 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe",
                 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'}
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = self.iface)
	log.info('Sending DHCP discover and DHCP request.')
	cip, sip = self.send_recv()
	mac = self.dhcp.get_mac(cip)[0]
	log.info("Sending DHCP request again.")
	new_cip, new_sip = self.dhcp.only_request(cip, mac)
	if (new_cip,new_sip) == (cip,sip):
		log.info('Got same ip for 2nd DHCP Request for client IP %s from server %s for mac %s.'
			  % (new_cip, new_sip, mac) )
	elif (new_cip,new_sip):
                log.info('No DHCP ACK')
                assert_equal(new_cip, None)
                assert_equal(new_sip, None)
	else:
		log.info('Something went wrong.')

    def test_dhcp_client_desired_address(self):
	config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
                 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
                 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip = '20.20.20.31', iface = self.iface)
	cip, sip, mac, _ = self.dhcp.only_discover(desired = True)
	log.info('Got dhcp client IP %s from server %s for mac %s .' %
		  (cip, sip, mac) )
	if cip == self.dhcp.seed_ip:
		log.info('Got dhcp client IP %s from server %s for mac %s as desired .' %
		  (cip, sip, mac) )
	elif cip != self.dhcp.seed_ip:
		log.info('Got dhcp client IP %s from server %s for mac %s .' %
		  (cip, sip, mac) )
		log.info('The desired ip was: %s .' % self.dhcp.seed_ip)
		assert_equal(cip, self.dhcp.seed_ip)

    def test_dhcp_client_desired_address_out_of_pool(self):
	config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
                 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
                 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip = '20.20.20.35', iface = self.iface)
	cip, sip, mac, _ = self.dhcp.only_discover(desired = True)
	log.info('Got dhcp client IP %s from server %s for mac %s .' %
		  (cip, sip, mac) )
	if cip == self.dhcp.seed_ip:
		log.info('Got dhcp client IP %s from server %s for mac %s as desired .' %
		  (cip, sip, mac) )
		assert_equal(cip, self.dhcp.seed_ip) #Negative Test Case
	elif cip != self.dhcp.seed_ip:
		log.info('Got dhcp client IP %s from server %s for mac %s .' %
		  (cip, sip, mac) )
		log.info('The desired ip was: %s .' % self.dhcp.seed_ip)
		assert_not_equal(cip, self.dhcp.seed_ip)
	elif cip == None:
		log.info('Got DHCP NAK')


    def test_dhcp_server_nak_packet(self):
	config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
                 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
                 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
	cip, sip, mac, _ = self.dhcp.only_discover()
	log.info('Got dhcp client IP %s from server %s for mac %s .' %
		  (cip, sip, mac) )

	log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
	if (cip == None and mac != None):
		log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
		assert_not_equal(cip, None)
	else:
		new_cip, new_sip = self.dhcp.only_request('20.20.20.31', mac)
		if new_cip == None:

			log.info("Got DHCP server NAK.")
			assert_equal(new_cip, None)  #Negative Test Case


    def test_dhcp_lease_packet(self):
	config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
                 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
                 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
	log.info('Sending DHCP discover with lease time of 700')
	cip, sip, mac, lval = self.dhcp.only_discover(lease_time = True)

	log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
	if (cip == None and mac != None):
		log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
		assert_not_equal(cip, None)
	elif lval != 700:
		log.info('Getting dhcp client IP %s from server %s for mac %s with lease time %s. That is not 700.' %
		 	 (cip, sip, mac, lval) )
		assert_not_equal(lval, 700)

    def test_dhcp_client_request_after_reboot(self):
	config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
                 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
                 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
	cip, sip, mac, _ = self.dhcp.only_discover()
	log.info('Got dhcp client IP %s from server %s for mac %s .' %
		  (cip, sip, mac) )

	log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")

	if (cip == None and mac != None):
		log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
		assert_not_equal(cip, None)

	else:
		new_cip, new_sip = self.dhcp.only_request(cip, mac)
		if new_cip == None:
			log.info("Got DHCP server NAK.")
		os.system('ifconfig '+self.iface+' down')
		log.info('Client goes down.')
		log.info('Delay for 5 seconds.')

		time.sleep(5)

		os.system('ifconfig '+self.iface+' up')
		log.info('Client is up now.')

		new_cip, new_sip = self.dhcp.only_request(cip, mac, cl_reboot = True)
		if new_cip == None:
			log.info("Got DHCP server NAK.")
			assert_not_equal(new_cip, None)
		elif new_cip != None:
			log.info("Got DHCP ACK.")
		os.system('ifconfig '+self.iface+' up')




    def test_dhcp_server_after_reboot(self):
	config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
                 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
                 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
	cip, sip, mac, _ = self.dhcp.only_discover()
	log.info('Got dhcp client IP %s from server %s for mac %s .' %
		  (cip, sip, mac) )

	log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")

	if (cip == None and mac != None):
		log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
		assert_not_equal(cip, None)

	else:
		new_cip, new_sip = self.dhcp.only_request(cip, mac)
		if new_cip == None:
			log.info("Got DHCP server NAK.")
			assert_not_equal(new_cip, None)
		log.info('Getting DHCP server Down.')

		self.onos_ctrl.deactivate()

		for i in range(0,4):
			log.info("Sending DHCP Request.")
			log.info('')
			new_cip, new_sip = self.dhcp.only_request(cip, mac)
			if new_cip == None and new_sip == None:
				log.info('')
				log.info("DHCP Request timed out.")
			elif new_cip and new_sip:
				log.info("Got Reply from DHCP server.")
				assert_equal(new_cip,None) #Neagtive Test Case

		log.info('Getting DHCP server Up.')

		status, _ = self.onos_ctrl.activate()
        	assert_equal(status, True)
        	time.sleep(3)

		for i in range(0,4):
			log.info("Sending DHCP Request after DHCP server is up.")
			log.info('')
			new_cip, new_sip = self.dhcp.only_request(cip, mac)
			if new_cip == None and new_sip == None:
				log.info('')
				log.info("DHCP Request timed out.")
			elif new_cip and new_sip:
				log.info("Got Reply from DHCP server.")
				assert_equal(new_cip,None) #Neagtive Test Case


    def test_dhcp_specific_lease_packet(self):
	config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
                 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
                 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
	log.info('Sending DHCP discover with lease time of 700')
	cip, sip, mac, _ = self.dhcp.only_discover(lease_time = True)
	log.info('Got dhcp client IP %s from server %s for mac %s .' %
		  (cip, sip, mac) )

	log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
	if (cip == None and mac != None):
		log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
		assert_not_equal(cip, None)
	elif cip and sip and mac:

		log.info("Triggering DHCP Request.")
		new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True)
		log.info('Getting dhcp client IP %s from server %s for mac %s with lease time %s. That is not 700.' %
		 	 (new_cip, new_sip, mac, lval) )
		assert_not_equal(lval, 700) #Negative Test Case



    def test_dhcp_lease_packet(self):
	config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
                 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
                 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
	cip, sip, mac, _ = self.dhcp.only_discover()
	log.info('Got dhcp client IP %s from server %s for mac %s .' %
		  (cip, sip, mac) )

	log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
	if (cip == None and mac != None):
		log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
		assert_not_equal(cip, None)

	elif cip and sip and mac:

		log.info("Triggering DHCP Request.")
		new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True)
		if lval == 600:
			log.info('Getting dhcp client IP %s from server %s for mac %s with lease time %s.' %
		 		 (new_cip, new_sip, mac, lval) )
		else:
			log.info('Getting dhcp client IP %s from server %s for mac %s with lease time %s.' %
		 		 (new_cip, new_sip, mac, lval) )
			log.info('The lease time suppossed to be 600 secs or 10 mins.')
			assert_equal(lval, 600)

    def test_dhcp_client_renew_time(self):

	config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
                 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
                 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
	cip, sip, mac, _ = self.dhcp.only_discover()
	log.info('Got dhcp client IP %s from server %s for mac %s .' %
		  (cip, sip, mac) )

	log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
	if (cip == None and mac != None):
		log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
		assert_not_equal(cip, None)

	elif cip and sip and mac:

		log.info("Triggering DHCP Request.")
		new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, renew_time = True)

		if new_cip and new_sip and lval:

			log.info("Clinet 's Renewal time is :%s",lval)
			log.info("Generating delay till renewal time.")
			time.sleep(lval)

			log.info("Client Sending Unicast DHCP request.")
			latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac, unicast = True)

			if latest_cip and latest_sip:
				log.info("Got DHCP Ack. Lease Renewed for ip %s and mac %s from server %s." %
						(latest_cip, mac, latest_sip) )

			elif latest_cip == None:
				log.info("Got DHCP NAK. Lease not renewed.")

		elif new_cip == None or new_sip == None or lval == None:

			log.info("Got DHCP NAK.")



    def test_dhcp_client_rebind_time(self):

	config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
                 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
                 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
	cip, sip, mac, _ = self.dhcp.only_discover()
	log.info('Got dhcp client IP %s from server %s for mac %s .' %
		  (cip, sip, mac) )

	log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
	if (cip == None and mac != None):
		log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
		assert_not_equal(cip, None)

	elif cip and sip and mac:

		log.info("Triggering DHCP Request.")
		new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, rebind_time = True)

		if new_cip and new_sip and lval:

			log.info("Clinet 's Rebind time is :%s",lval)
			log.info("Generating delay till rebind time.")
			time.sleep(lval)

			log.info("Client Sending broadcast DHCP requests for renewing lease or for getting new ip.")

			for i in range(0,4):
				latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac)

				if latest_cip and latest_sip:
					log.info("Got DHCP Ack. Lease Renewed for ip %s and mac %s from server %s." %
							(latest_cip, mac, latest_sip) )
					break

				elif latest_cip == None:
					log.info("Got DHCP NAK. Lease not renewed.")
			assert_not_equal(latest_cip, None)
		elif new_cip == None or new_sip == None or lval == None:

			log.info("Got DHCP NAK.Lease not Renewed.")


    def test_dhcp_client_expected_subnet_mask(self):

	config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
                 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
                 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
	expected_subnet = '255.255.255.0'
	self.dhcp.return_option = 'subnet'

	cip, sip, mac, subnet_value = self.dhcp.only_discover()
	log.info('Got dhcp client IP %s from server %s for mac %s .' %
		  (cip, sip, mac) )

	log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
	if (cip == None and mac != None):
		log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
		assert_not_equal(cip, None)

	elif cip and sip and mac:

		if expected_subnet == subnet_value:
			log.info("Got same subnet as passed in DHCP server configuration.")

		elif expected_subnet != subnet_value:
			log.info("Not getting same subnet as passed in DHCP server configuration.")
			assert_equal(expected_subnet, subnet_value)


    def test_dhcp_client_sends_dhcp_request_with_wrong_subnet_mask(self):

	config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
                 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
                 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)

	cip, sip, mac, _ = self.dhcp.only_discover()
	log.info('Got dhcp client IP %s from server %s for mac %s .' %
		  (cip, sip, mac) )

	log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
	if (cip == None and mac != None):
		log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
		assert_not_equal(cip, None)

	elif cip and sip and mac:

		self.dhcp.send_different_option = 'subnet'
		log.info("Sending DHCP Request with wrong subnet mask.")
		new_cip, new_sip = self.dhcp.only_request(cip, mac)
		if new_cip == None:

			log.info("Got DHCP NAK.")
			assert_not_equal(new_cip, None)

		elif new_cip and new_sip:

			log.info("Got DHCP Ack despite of specifying wrong Subnet Mask in DHCP Request.")
			log.info("Getting subnet mask as per server 's configuration.")


    def test_dhcp_client_expected_router_address(self):

	config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
                 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
                 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
	expected_router_address = '20.20.20.1'
	self.dhcp.return_option = 'router'

	cip, sip, mac, router_address_value = self.dhcp.only_discover()
	log.info('Got dhcp client IP %s from server %s for mac %s .' %
		  (cip, sip, mac) )

	log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
	if (cip == None and mac != None):
		log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
		assert_not_equal(cip, None)

	elif cip and sip and mac:

		if expected_router_address == router_address_value:
			log.info("Got same router address as passed in DHCP server configuration.")

		elif expected_router_address != router_address_value:
			log.info("Not getting same router address as passed in DHCP server configuration.")
			assert_equal(expected_router_address, router_address_value)


    def test_dhcp_client_sends_dhcp_request_with_wrong_router_address(self):

	config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
                 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
                 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)

	cip, sip, mac, _ = self.dhcp.only_discover()
	log.info('Got dhcp client IP %s from server %s for mac %s .' %
		  (cip, sip, mac) )

	log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
	if (cip == None and mac != None):
		log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
		assert_not_equal(cip, None)

	elif cip and sip and mac:

		self.dhcp.send_different_option = 'router'
		log.info("Sending DHCP Request with wrong router address.")
		new_cip, new_sip = self.dhcp.only_request(cip, mac)
		if new_cip == None:

			log.info("Got DHCP NAK.")
			assert_not_equal(new_cip, None)

		elif new_cip and new_sip:

			log.info("Got DHCP Ack despite of specifying wrong Router Address in DHCP Request.")
			log.info("Getting Router Address as per server 's configuration.")


    def test_dhcp_client_expected_broadcast_address(self):

	config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
                 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
                 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
	expected_broadcast_address = '20.20.20.255'
	self.dhcp.return_option = 'broadcast_address'

	cip, sip, mac, broadcast_address_value = self.dhcp.only_discover()
	log.info('Got dhcp client IP %s from server %s for mac %s .' %
		  (cip, sip, mac) )

	log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
	if (cip == None and mac != None):
		log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
		assert_not_equal(cip, None)

	elif cip and sip and mac:

		if expected_broadcast_address == broadcast_address_value:
			log.info("Got same router address as passed in DHCP server configuration.")

		elif expected_broadcast_address != broadcast_address_value:
			log.info("Not getting same router address as passed in DHCP server configuration.")
			assert_equal(expected_broadcast_address, broadcast_address_value)


    def test_dhcp_client_sends_dhcp_request_with_wrong_broadcast_address(self):

	config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
                 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
                 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)

	cip, sip, mac, _ = self.dhcp.only_discover()
	log.info('Got dhcp client IP %s from server %s for mac %s .' %
		  (cip, sip, mac) )

	log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
	if (cip == None and mac != None):
		log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
		assert_not_equal(cip, None)

	elif cip and sip and mac:

		self.dhcp.send_different_option = 'broadcast_address'
		log.info("Sending DHCP Request with wrong broadcast address.")
		new_cip, new_sip = self.dhcp.only_request(cip, mac)
		if new_cip == None:

			log.info("Got DHCP NAK.")
			assert_not_equal(new_cip, None)

		elif new_cip and new_sip:

			log.info("Got DHCP Ack despite of specifying wrong Broadcast Address in DHCP Request.")
			log.info("Getting Broadcast Address as per server 's configuration.")

    def test_dhcp_client_expected_dns_address(self):

	config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
                 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
                 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1', 'domain':'8.8.8.8'}
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
	expected_dns_address = '8.8.8.8'
	self.dhcp.return_option = 'dns'

	cip, sip, mac, dns_address_value = self.dhcp.only_discover()
	log.info('Got dhcp client IP %s from server %s for mac %s .' %
		  (cip, sip, mac) )

	log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
	if (cip == None and mac != None):
		log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
		assert_not_equal(cip, None)

	elif cip and sip and mac:

		if expected_dns_address == dns_address_value:
			log.info("Got same DNS address as passed in DHCP server configuration.")

		elif expected_dns_address != dns_address_value:
			log.info("Not getting same DNS address as passed in DHCP server configuration.")
			assert_equal(expected_dns_address, dns_address_value)


    def test_dhcp_client_sends_request_with_wrong_dns_address(self):

	config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
                 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
                 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1', 'domain':'8.8.8.8'}
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)

	cip, sip, mac, _ = self.dhcp.only_discover()
	log.info('Got dhcp client IP %s from server %s for mac %s .' %
		  (cip, sip, mac) )

	log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
	if (cip == None and mac != None):
		log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
		assert_not_equal(cip, None)

	elif cip and sip and mac:

		self.dhcp.send_different_option = 'dns'
		log.info("Sending DHCP Request with wrong DNS address.")
		new_cip, new_sip = self.dhcp.only_request(cip, mac)
		if new_cip == None:
			log.info("Got DHCP NAK.")
			assert_not_equal(new_cip, None)
		elif new_cip and new_sip:
			log.info("Got DHCP Ack despite of specifying wrong DNS Address in DHCP Request.")
			log.info("Getting DNS Address as per server 's configuration.")

    def test_dhcp_server_transactions_per_second(self):

	for i in range(1,4):
		self.stats()
		log.info("Stats for run %d",i)
		log.info("----------------------------------------------------------------------------------")
		log.info("No. of transactions     No. of successes     No. of failures     Running Time ")
	        log.info("    %d                    %d                     %d                  %d" %(self.ip_count+self.failure_count, 		               self.ip_count, self.failure_count, self.diff))
		log.info("----------------------------------------------------------------------------------")
		log.info("No. of transactions per second in run %d:%f" %(i, self.transaction_count))

	log.info("Final Statistics for total transactions")
	log.info("----------------------------------------------------------------------------------")
	log.info("Total transactions     Total No. of successes     Total No. of failures     Running Time ")
	log.info("    %d                     %d                         %d                        %d" %(self.transactions,
                 self.total_success, self.total_failure, self.running_time))
	log.info("----------------------------------------------------------------------------------")
	log.info("Average no. of transactions per second: %d", round(self.transactions/self.running_time,0))

    def test_dhcp_server_consecutive_successes_per_second(self):

	for i in range(1,4):
		self.stats(success_rate = True)
		log.info("Stats for run %d",i)
		log.info("----------------------------------------------------------------------------------")
		log.info("No. of consecutive successful transactions          Running Time ")
	        log.info("                   %d                                   %d        " %(self.ip_count, self.diff))
		log.info("----------------------------------------------------------------------------------")
		log.info("No. of successful transactions per second in run %d:%f" %(i, self.transaction_count))
		log.info("----------------------------------------------------------------------------------")

	log.info("Final Statistics for total successful transactions")
	log.info("----------------------------------------------------------------------------------")
	log.info("Total transactions     Total No. of consecutive successes         Running Time ")
	log.info("    %d                                 %d                             %d        " %(self.transactions,
                 self.total_success, self.running_time))
	log.info("----------------------------------------------------------------------------------")
	log.info("Average no. of consecutive successful transactions per second: %d", round(self.total_success/self.running_time,0))
	log.info("----------------------------------------------------------------------------------")


    def test_dhcp_server_client_transactions_per_second(self):

        for i in range(1,4):
		self.stats(only_discover = True)
		log.info("----------------------------------------------------------------------------------")
		log.info("Stats for run %d of sending only DHCP Discover",i)
		log.info("----------------------------------------------------------------------------------")
		log.info("No. of transactions     No. of successes     No. of failures     Running Time ")
	        log.info("    %d                    %d                     %d                  %d" %(self.ip_count+self.failure_count, 		               self.ip_count, self.failure_count, self.diff))
		log.info("----------------------------------------------------------------------------------")
		log.info("No. of clients per second in run %d:%f                                      "
			%(i, self.transaction_count))
		log.info("----------------------------------------------------------------------------------")
	log.info("Final Statistics for total transactions of sending only DHCP Discover")
	log.info("----------------------------------------------------------------------------------")
	log.info("Total transactions     Total No. of successes     Total No. of failures     Running Time ")
	log.info("    %d                     %d                         %d                        %d" %(self.transactions,
                 self.total_success, self.total_failure, self.running_time))
	log.info("----------------------------------------------------------------------------------")
	log.info("Average no. of clients per second: %d                                        ",
		round(self.transactions/self.running_time,0))
	log.info("----------------------------------------------------------------------------------")

    def test_dhcp_server_consecutive_successful_clients_per_second(self):

        for i in range(1,4):
		self.stats(success_rate = True, only_discover = True)
		log.info("----------------------------------------------------------------------------------")
		log.info("Stats for run %d for sending only DHCP Discover",i)
		log.info("----------------------------------------------------------------------------------")
		log.info("No. of consecutive successful transactions          Running Time ")
	        log.info("                   %d                                   %d        " %(self.ip_count, self.diff))
		log.info("----------------------------------------------------------------------------------")
		log.info("No. of consecutive successful clients per second in run %d:%f" %(i, self.transaction_count))
		log.info("----------------------------------------------------------------------------------")

	log.info("Final Statistics for total successful transactions")
	log.info("----------------------------------------------------------------------------------")
	log.info("Total transactions     Total No. of consecutive successes         Running Time ")
	log.info("    %d                                 %d                             %d        " %(self.transactions,
                 self.total_success, self.running_time))
	log.info("----------------------------------------------------------------------------------")
	log.info("Average no. of consecutive successful clients per second: %d", round(self.total_success/self.running_time,0))
	log.info("----------------------------------------------------------------------------------")
Exemplo n.º 33
0
 def get_flows(cls, device_id,controller=None):
     return OnosCtrl.get_flows(device_id,controller=controller)
Exemplo n.º 34
0
 def host_config_load(cls, host_config=None):
     for host in host_config:
         status, code = OnosCtrl.host_config(host)
         if status is False:
             log_test.info('JSON request returned status %d' % code)
             assert_equal(status, True)
Exemplo n.º 35
0
 def onos_load_config(self, config):
     status, code = OnosCtrl.config(config)
     if status is False:
         log.info('JSON config request returned status %d' %code)
     time.sleep(2)
Exemplo n.º 36
0
class IgmpChannel:

    IGMP_DST_MAC = "01:00:5e:00:01:01"
    IGMP_SRC_MAC = "5a:e1:ac:ec:4d:a1"
    IP_SRC = '1.2.3.4'
    IP_DST = '224.0.1.1'
    igmp_eth = Ether(dst = IGMP_DST_MAC, src = IGMP_SRC_MAC, type = ETH_P_IP)
    igmp_ip = IP(dst = IP_DST, src = IP_SRC)
    ssm_list = []

    def __init__(self, iface = 'veth0', ssm_list = [], src_list = ['1.2.3.4'], delay = 2):
        self.iface = iface
        self.ssm_list += ssm_list
        self.src_list = src_list
        self.delay = delay
        self.onos_ctrl = OnosCtrl('org.onosproject.igmp')
        self.onos_ctrl.activate()

    def igmp_load_ssm_config(self, ssm_list = []):
        if not ssm_list:
            ssm_list = self.ssm_list
        self.ssm_table_load(ssm_list)

    def igmp_join(self, groups):
        igmp = IGMPv3(type = IGMP_TYPE_V3_MEMBERSHIP_REPORT, max_resp_code=30,
                      gaddr='224.0.1.1')
        for g in groups:
              gr = IGMPv3gr(rtype=IGMP_V3_GR_TYPE_INCLUDE, mcaddr=g)
              gr.sources = self.src_list
              igmp.grps.append(gr)

        pkt = self.igmp_eth/self.igmp_ip/igmp
        IGMPv3.fixup(pkt)
        sendp(pkt, iface=self.iface)
        if self.delay != 0:
            time.sleep(self.delay)

    def igmp_leave(self, groups):
        igmp = IGMPv3(type = IGMP_TYPE_V3_MEMBERSHIP_REPORT, max_resp_code=30,
                      gaddr='224.0.1.1')
        for g in groups:
              gr = IGMPv3gr(rtype=IGMP_V3_GR_TYPE_EXCLUDE, mcaddr=g)
              gr.sources = self.src_list
              igmp.grps.append(gr)

        pkt = self.igmp_eth/self.igmp_ip/igmp
        IGMPv3.fixup(pkt)
        sendp(pkt, iface = self.iface)
        if self.delay != 0:
            time.sleep(self.delay)

    def onos_load_config(self, config):
        status, code = OnosCtrl.config(config)
        if status is False:
            log.info('JSON config request returned status %d' %code)
        time.sleep(2)

    def ssm_table_load(self, groups):
          ssm_dict = {'apps' : { 'org.onosproject.igmp' : { 'ssmTranslate' : [] } } }
          ssm_xlate_list = ssm_dict['apps']['org.onosproject.igmp']['ssmTranslate']
          for g in groups:
                for s in self.src_list:
                      d = {}
                      d['source'] = s
                      d['group'] = g
                      ssm_xlate_list.append(d)
          self.onos_load_config(ssm_dict)

    def cord_port_table_load(self, cord_port_map):
          cord_group_dict = {'apps' : { 'org.ciena.cordigmp' : { 'cordIgmpTranslate' : [] } } }
          cord_group_xlate_list = cord_group_dict['apps']['org.ciena.cordigmp']['cordIgmpTranslate']
          for group, ports in cord_port_map.items():
              d = {}
              d['group'] = group
              d['inputPort'] = ports[0]
              d['outputPort'] = ports[1]
              cord_group_xlate_list.append(d)
          self.onos_load_config(cord_group_dict)
Exemplo n.º 37
0
 def onos_load_config(cls, config):
     status, code = OnosCtrl.config(config)
     if status is False:
         log.info('JSON request returned status %d' %code)
         assert_equal(status, True)
Exemplo n.º 38
0
def setup_module(module):
    class_test = get_test_class(module)
    assert_not_equal(class_test, None)
    module_name = module.__name__.split('.')[-1]
    cfg = '{}.json'.format(module_name)
    module_config = os.path.join(os.path.dirname(module.__file__), cfg)
    if os.access(module_config, os.F_OK):
        with open(module_config) as f:
            json_data = json.load(f)
            for k, v in json_data.iteritems():
                setattr(class_test, k, v)

    #check for voltha and configure as appropriate
    voltha_attrs = dict(
        host=VolthaService.DOCKER_HOST_IP,
        ponsim_host=VolthaService.PONSIM_HOST,
        rest_port=VolthaCtrl.REST_PORT,
        config_fake=False,
        olt_type='ponsim_olt',
        olt_mac='00:0c:e2:31:12:00',
        olt_ip=None,
        uplink_vlan_map={'of:0000000000000001': '222'},
        uplink_vlan_start=333,
        teardown=True,
    )
    voltha_enabled = bool(int(os.getenv('VOLTHA_ENABLED', 0)))
    voltha_configure = True

    olt_switch_map = {}

    if hasattr(class_test, 'VOLTHA_AUTO_CONFIGURE'):
        voltha_configure = getattr(class_test, 'VOLTHA_AUTO_CONFIGURE')

    tagged_traffic = False
    if hasattr(class_test, 'TAGGED_TRAFFIC'):
        tagged_traffic = getattr(class_test, 'TAGGED_TRAFFIC')

    if hasattr(class_test, 'VOLTHA_HOST'):
        #update the voltha host ip based on chameleon IP for rest interface
        rest_interface = VolthaService.get_ip('chameleon')
        if rest_interface:
            log.info('Updating VOLTHA_HOST IP to %s' % rest_interface)
            setattr(class_test, 'VOLTHA_HOST', rest_interface)

    if voltha_enabled and voltha_configure:
        for k, v in voltha_attrs.iteritems():
            voltha_attr = 'VOLTHA_{}'.format(k.upper())
            if hasattr(class_test, voltha_attr):
                v = getattr(class_test, voltha_attr)
                voltha_attrs[k] = v
            else:
                setattr(class_test, voltha_attr, v)
        ret = voltha_setup(**voltha_attrs)
        if ret is not None:
            #setup the stage to drop voltha on the way out
            setattr(class_test, 'voltha_ctrl', ret[0])
            setattr(class_test, 'voltha_device', ret[1])
            setattr(class_test, 'voltha_switch_map', ret[2])
            olt_switch_map = ret[2]
            voltha_driver_configured = ret[3]
            setattr(class_test, 'voltha_preconfigured',
                    voltha_driver_configured)
            if voltha_driver_configured:
                setattr(class_test, 'VOLTHA_TEARDOWN', False)

    #load the sadis and aaa config
    OnosCtrl.sadis_load_config(olt_switch_map=olt_switch_map,
                               tagged_traffic=tagged_traffic)
    OnosCtrl.aaa_load_config()
    #OnosCtrl('org.opencord.aaa').deactivate()
    #time.sleep(3)
    #OnosCtrl('org.opencord.aaa').activate()
    #time.sleep(3)
    if voltha_enabled is False:
        OnosCtrl.config_olt_access(VolthaCtrl.UPLINK_VLAN_START)
Exemplo n.º 39
0
 def onos_load_config(self, config):
     status, code = OnosCtrl.config(config, controller=self.controller)
     if status is False:
         log_test.info('JSON config request returned status %d' % code)
     time.sleep(2)
Exemplo n.º 40
0
 def onos_load_config(self, config):
     status, code = OnosCtrl.config(config)
     if status is False:
         log_test.info('JSON request returned status %d' % code)
         assert_equal(status, True)
     time.sleep(3)
Exemplo n.º 41
0
class IgmpChannel:

    IGMP_DST_MAC = "01:00:5e:00:01:01"
    IGMP_SRC_MAC = "5a:e1:ac:ec:4d:a1"
    IP_SRC = '1.2.3.4'
    IP_DST = '224.0.1.1'
    igmp_eth = Ether(dst=IGMP_DST_MAC, src=IGMP_SRC_MAC, type=ETH_P_IP)
    igmp_ip = IP(dst=IP_DST, src=IP_SRC)
    ssm_list = []

    def __init__(self,
                 iface='veth0',
                 ssm_list=[],
                 src_list=None,
                 delay=2,
                 controller=None):

        self.controller = controller
        self.iface = iface
        self.ssm_list += ssm_list
        if src_list is None:
            self.src_list = ['1.2.3.4']
        else:
            self.src_list = src_list
        self.delay = delay
        self.onos_ctrl = OnosCtrl('org.opencord.igmp',
                                  controller=self.controller)
        self.onos_ctrl.activate()

    def igmp_load_ssm_config(self, ssm_list=[], src_list=None):
        if src_list is None:
            src_list = self.src_list
        if not ssm_list:
            ssm_list = self.ssm_list
        self.ssm_table_load(ssm_list, src_list=src_list)

    def igmp_join(self, groups, src_list=None, record_type=None):
        if src_list is None:
            src_list = self.src_list
        if record_type is None:
            record_type = IGMP_V3_GR_TYPE_INCLUDE
        igmp = IGMPv3(type=IGMP_TYPE_V3_MEMBERSHIP_REPORT,
                      max_resp_code=30,
                      gaddr='224.0.1.1')
        for g in groups:
            gr = IGMPv3gr(rtype=record_type, mcaddr=g)
            gr.sources = src_list
            igmp.grps.append(gr)

        pkt = self.igmp_eth / self.igmp_ip / igmp
        IGMPv3.fixup(pkt)
        sendp(pkt, iface=self.iface)
        if self.delay != 0:
            time.sleep(self.delay)

    def igmp_leave(self, groups, src_list=None):
        if src_list is None:
            src_list = self.src_list
        igmp = IGMPv3(type=IGMP_TYPE_V3_MEMBERSHIP_REPORT,
                      max_resp_code=30,
                      gaddr='224.0.1.1')
        for g in groups:
            gr = IGMPv3gr(rtype=IGMP_V3_GR_TYPE_EXCLUDE, mcaddr=g)
            gr.sources = src_list
            igmp.grps.append(gr)

        pkt = self.igmp_eth / self.igmp_ip / igmp
        IGMPv3.fixup(pkt)
        sendp(pkt, iface=self.iface)
        if self.delay != 0:
            time.sleep(self.delay)

    def onos_load_config(self, config):
        status, code = OnosCtrl.config(config, controller=self.controller)
        if status is False:
            log_test.info('JSON config request returned status %d' % code)
        time.sleep(2)

    def ssm_table_load(self, groups, src_list=None):
        return
        if src_list is None:
            src_list = self.src_list
        ssm_dict = {'apps': {'org.opencord.igmp': {'ssmTranslate': []}}}
        ssm_xlate_list = ssm_dict['apps']['org.opencord.igmp']['ssmTranslate']
        for g in groups:
            for s in src_list:
                d = {}
                d['source'] = s
                d['group'] = g
                ssm_xlate_list.append(d)
        self.onos_load_config(ssm_dict)

    def cord_port_table_load(self, cord_port_map):
        return
        cord_group_dict = {
            'apps': {
                'org.ciena.cordigmp': {
                    'cordIgmpTranslate': []
                }
            }
        }
        cord_group_xlate_list = cord_group_dict['apps']['org.ciena.cordigmp'][
            'cordIgmpTranslate']
        for group, ports in cord_port_map.items():
            d = {}
            d['group'] = group
            d['inputPort'] = ports[0]
            d['outputPort'] = ports[1]
            cord_group_xlate_list.append(d)
        self.onos_load_config(cord_group_dict)
Exemplo n.º 42
0
 def uninstall_app_table(cls):
       ##Uninstall the table app on class exit
       OnosCtrl.uninstall_app(cls.table_app)
       time.sleep(2)
       log.info('Installing back the cord igmp app %s for subscriber test on exit' %(cls.app_file))
       OnosCtrl.install_app(cls.app_file)
Exemplo n.º 43
0
def runTest(args):
    #Start the cord test tcp server
    test_server_params = args.server.split(':')
    test_host = test_server_params[0]
    test_port = CORD_TEST_PORT
    if len(test_server_params) > 1:
        test_port = int(test_server_params[1])
    try:
        test_server = cord_test_server_start(daemonize = False, cord_test_host = test_host, cord_test_port = test_port)
    except:
        ##Most likely a server instance is already running (daemonized earlier)
        test_server = None

    test_containers = []
    #These tests end up restarting ONOS/quagga/radius
    tests_exempt = ('vrouter', 'cordSubscriber', 'proxyarp')
    if args.test_type.lower() == 'all':
        tests = CordTester.ALL_TESTS
        args.quagga = True
    else:
        tests = args.test_type.split('-')

    tests_parallel = [ t for t in tests if t.split(':')[0] not in tests_exempt ]
    tests_not_parallel = [ t for t in tests if t.split(':')[0] in tests_exempt ]
    onos_cnt = {'tag':'latest'}
    nose_cnt = {'image': CordTester.IMAGE, 'tag': 'latest'}
    update_map = { 'quagga' : False, 'test' : False, 'radius' : False }
    update_map[args.update.lower()] = True

    if args.update.lower() == 'all':
       for c in update_map.keys():
           update_map[c] = True

    radius_ip = None

    #don't spawn onos if the user has specified external test controller with test interface config
    if args.test_controller:
        ips = args.test_controller.split('/')
        onos_ip = ips[0]
        if len(ips) > 1:
            radius_ip = ips[1]
        else:
            radius_ip = None
    else:
        onos_cnt['image'] = args.onos.split(':')[0]
        if args.onos.find(':') >= 0:
            onos_cnt['tag'] = args.onos.split(':')[1]

        onos = Onos(image = onos_cnt['image'], tag = onos_cnt['tag'], boot_delay = 60)
        onos_ip = onos.ip()

    print('Onos IP %s, Test type %s' %(onos_ip, args.test_type))
    if args.test_controller:
        print('Installing ONOS cord apps')
        Onos.install_cord_apps(onos_ip = onos_ip)

    print('Installing cord tester ONOS app %s' %onos_app_file)
    OnosCtrl.install_app(args.app, onos_ip = onos_ip)

    if radius_ip is None:
        ##Start Radius container
        radius = Radius( update = update_map['radius'])
        radius_ip = radius.ip()

    print('Radius server running with IP %s' %radius_ip)

    if args.quagga == True:
        #Start quagga. Builds container if required
        quagga = Quagga(update = update_map['quagga'])

    test_cnt_env = { 'ONOS_CONTROLLER_IP' : onos_ip,
                     'ONOS_AAA_IP' : radius_ip if radius_ip is not None else '',
                     'QUAGGA_IP': test_host,
                     'CORD_TEST_HOST' : test_host,
                     'CORD_TEST_PORT' : test_port,
                     'ONOS_RESTART_DISABLED' : 1 if args.olt and args.test_controller else 0,
                   }
    if args.olt:
        olt_conf_test_loc = os.path.join(CordTester.sandbox_setup, 'olt_config.json')
        test_cnt_env['OLT_CONFIG'] = olt_conf_test_loc

    port_num = 0
    num_tests = len(tests_parallel)
    tests_per_container = max(1, num_tests/args.num_containers)
    test_slice_start = 0
    test_slice_end = test_slice_start + tests_per_container
    num_test_containers = min(num_tests, args.num_containers)
    if tests_parallel:
        print('Running %s tests across %d containers in parallel' %(tests_parallel, num_test_containers))
    for container in range(num_test_containers):
        test_cnt = CordTester(tests_parallel[test_slice_start:test_slice_end],
                              instance = container, num_instances = num_test_containers,
                              ctlr_ip = onos_ip, image = nose_cnt['image'], tag = nose_cnt['tag'],
                              env = test_cnt_env,
                              rm = False if args.keep else True,
                              update = update_map['test'])
        test_slice_start = test_slice_end
        test_slice_end = test_slice_start + tests_per_container
        update_map['test'] = False
        test_containers.append(test_cnt)
        if args.start_switch or not args.olt:
            test_cnt.start_switch()
        if test_cnt.olt:
            _, port_num = test_cnt.setup_intfs(port_num = port_num)

    thread_pool = ThreadPool(len(test_containers), queue_size = 1, wait_timeout=1)
    for test_cnt in test_containers:
        thread_pool.addTask(test_cnt.run_tests)
    thread_pool.cleanUpThreads()

    ##Run the linear tests
    if tests_not_parallel:
        test_cnt = CordTester(tests_not_parallel,
                              ctlr_ip = onos_ip, image = nose_cnt['image'], tag = nose_cnt['tag'],
                              env = test_cnt_env,
                              rm = False if args.keep else True,
                              update = update_map['test'])
        if args.start_switch or not args.olt:
            test_cnt.start_switch()
        if test_cnt.olt:
            test_cnt.setup_intfs(port_num = port_num)
        test_cnt.run_tests()

    if test_server:
        cord_test_server_stop(test_server)
Exemplo n.º 44
0
def setupCordTester(args):
    onos_cnt = {'tag':'latest'}
    nose_cnt = {'image': CordTester.IMAGE, 'tag': 'latest'}
    update_map = { 'quagga' : False, 'radius' : False, 'test': False }
    update_map[args.update.lower()] = True

    if args.update.lower() == 'all':
       for c in update_map.keys():
           update_map[c] = True

    onos_ip = None
    radius_ip = None
    onos_cord_loc = args.onos_cord
    if onos_cord_loc:
        if onos_cord_loc.find(os.path.sep) < 0:
            onos_cord_loc = os.path.join(os.getenv('HOME'), onos_cord_loc)
        if not os.access(onos_cord_loc, os.F_OK):
            print('ONOS cord config location %s is not accessible' %onos_cord_loc)
            sys.exit(1)
        #Disable test container provisioning on the ONOS compute node
        args.dont_provision = True

    ##If onos/radius was already started
    if args.test_controller:
        ips = args.test_controller.split('/')
        onos_ip = ips[0]
        if len(ips) > 1:
            radius_ip = ips[1]
        else:
            radius_ip = None

    onos_cord = None
    if onos_cord_loc:
        if not args.test_controller:
            ##Unexpected case. Specify the external controller ip when running on cord node
            print('Specify ONOS ip using \"-e\" option when running the cord-tester on cord node')
            sys.exit(1)
        onos_cord = OnosCord(onos_ip, onos_cord_loc)

    #don't spawn onos if the user had started it externally
    onos_cnt['image'] = args.onos.split(':')[0]
    if args.onos.find(':') >= 0:
        onos_cnt['tag'] = args.onos.split(':')[1]

    if onos_ip is None:
        onos = Onos(image = onos_cnt['image'], tag = onos_cnt['tag'], boot_delay = 60)
        onos_ip = onos.ip()

    print('Onos IP %s' %onos_ip)
    if args.test_controller:
        print('Installing ONOS cord apps')
        Onos.install_cord_apps(onos_ip = onos_ip)

    print('Installing cord tester ONOS app %s' %onos_app_file)
    OnosCtrl.install_app(args.app, onos_ip = onos_ip)

    ##Start Radius container if not started
    if radius_ip is None:
        radius = Radius( update = update_map['radius'])
        radius_ip = radius.ip()

    print('Radius server running with IP %s' %radius_ip)

    if args.quagga == True:
        #Start quagga. Builds container if required
        quagga = Quagga(update = update_map['quagga'])
        print('Quagga started')

    params = args.server.split(':')
    ip = params[0]
    port = CORD_TEST_PORT
    if len(params) > 1:
        port = int(params[1])

    #provision the test container
    if not args.dont_provision:
        test_cnt_env = { 'ONOS_CONTROLLER_IP' : onos_ip,
                         'ONOS_AAA_IP' : radius_ip,
                         'QUAGGA_IP': ip,
                         'CORD_TEST_HOST' : ip,
                         'CORD_TEST_PORT' : port,
                         'ONOS_RESTART_DISABLED' : 1 if args.olt and args.test_controller else 0,
                       }
        if args.olt:
            olt_conf_test_loc = os.path.join(CordTester.sandbox_setup, 'olt_config.json')
            test_cnt_env['OLT_CONFIG'] = olt_conf_test_loc

        test_cnt = CordTester((),
                              ctlr_ip = onos_ip,
                              image = nose_cnt['image'],
                              tag = nose_cnt['tag'],
                              env = test_cnt_env,
                              rm = False,
                              update = update_map['test'])

        if args.start_switch or not args.olt:
            test_cnt.start_switch()
        if test_cnt.olt:
            test_cnt.setup_intfs(port_num = 0)
        print('Test container %s started and provisioned to run tests using nosetests' %(test_cnt.name))

    #Finally start the test server and daemonize
    cord_test_server_start(daemonize = True, cord_test_host = ip, cord_test_port = port,
                           onos_cord = onos_cord)
Exemplo n.º 45
0
 def tearDownClass(cls):
     onos_ctrl = OnosCtrl('org.onosproject.cpman')
     status, _ = onos_ctrl.deactivate()
Exemplo n.º 46
0
class dhcp_exchange(CordLogger):

    dhcp_server_config = {
        "ip": "10.1.11.50",
        "mac": "ca:fe:ca:fe:ca:fe",
        "subnet": "255.255.252.0",
        "broadcast": "10.1.11.255",
        "router": "10.1.8.1",
        "domain": "8.8.8.8",
        "ttl": "63",
        "delay": "2",
        "startip": "10.1.11.51",
        "endip": "10.1.11.100"
    }

    STARTIP = "10.10.10.40"
    ENDIP = "10.10.10.41"
    IP = "10.10.10.2"
    MAC = "ca:fe:ca:fe:ca:fe"
    SUBNET = "255.255.255.0"
    BROADCAST = "10.10.10.255"
    ROUTER = "10.10.10.1"

    app = 'org.onosproject.dhcp'

    ip_count = 0
    failure_count = 0
    start_time = 0
    diff = 0

    transaction_count = 0
    transactions = 0
    running_time = 0
    total_success = 0
    total_failure = 0

    @classmethod
    def setUpClass(cls):
        cls.config_dhcp = {
            'startip': cls.STARTIP,
            'endip': cls.ENDIP,
            'ip': cls.IP,
            'mac': cls.MAC,
            'subnet': cls.SUBNET,
            'broadcast': cls.BROADCAST,
            'router': cls.ROUTER
        }
        cls.olt = OltConfig()
        cls.port_map, _ = cls.olt.olt_port_map()
        if not cls.port_map:
            cls.port_map = g_subscriber_port_map
        cls.iface = cls.port_map[1]

    def setUp(self):
        ''' Activate the dhcp app'''
        super(dhcp_exchange, self).setUp()
        self.maxDiff = None  ##for assert_equal compare outputs on failure
        self.onos_ctrl = OnosCtrl(self.app)
        status, _ = self.onos_ctrl.activate()
        assert_equal(status, True)
        time.sleep(3)

    def tearDown(self):
        '''Deactivate the dhcp app'''
        self.onos_ctrl.deactivate()
        super(dhcp_exchange, self).tearDown()

    def onos_load_config(self, config):
        status, code = OnosCtrl.config(config)
        if status is False:
            log_test.info('JSON request returned status %d' % code)
            assert_equal(status, True)
        time.sleep(3)

    def onos_dhcp_table_load(self, config=None):
        dhcp_dict = {
            'apps': {
                'org.onosproject.dhcp': {
                    'dhcp': copy.copy(self.dhcp_server_config)
                }
            }
        }
        dhcp_config = dhcp_dict['apps']['org.onosproject.dhcp']['dhcp']
        if config:
            for k in config.keys():
                if dhcp_config.has_key(k):
                    dhcp_config[k] = config[k]
        self.onos_load_config(dhcp_dict)

    def send_recv(self, mac=None, update_seed=False, validate=True):
        cip, sip = self.dhcp.discover(mac=mac, update_seed=update_seed)
        log_test.info("discover cip %s" % (cip))
        log_test.info("discover sip %s" % (sip))
        if validate:
            assert_not_equal(cip, None)
            assert_not_equal(sip, None)
            log_test.info('Got dhcp client IP %s from server %s for mac %s' %
                          (cip, sip, self.dhcp.get_mac(cip)[0]))
        return cip, sip

    def stats(self, success_rate=False, only_discover=False):

        self.ip_count = 0
        self.failure_count = 0
        self.start_time = 0
        self.diff = 0
        self.transaction_count = 0
        config = {
            'startip': '182.17.0.3',
            'endip': '182.17.0.180',
            'ip': '182.17.0.2',
            'mac': "ca:fe:c3:fe:ca:fe",
            'subnet': '255.255.255.0',
            'broadcast': '182.17.0.255',
            'router': '182.17.0.1'
        }
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip='182.17.0.1', iface=self.iface)
        self.start_time = time.time()

        while self.diff <= 60:
            if only_discover:
                cip, sip, mac, _ = self.dhcp.only_discover(multiple=True)
                log_test.info(
                    'Got dhcp client IP %s from server %s for mac %s' %
                    (cip, sip, mac))
            else:
                cip, sip = self.send_recv(update_seed=True, validate=False)

            if cip:
                self.ip_count += 1
            elif cip == None:
                self.failure_count += 1
                log_test.info('Failed to get ip')
                if success_rate and self.ip_count > 0:
                    break
            self.diff = round(time.time() - self.start_time, 0)

        self.transaction_count = round(
            (self.ip_count + self.failure_count) / self.diff, 2)

        self.transactions += (self.ip_count + self.failure_count)
        self.running_time += self.diff
        self.total_success += self.ip_count
        self.total_failure += self.failure_count

    def test_dhcp_1request(self):
        self.onos_dhcp_table_load(self.config_dhcp)
        self.dhcp = DHCPTest(seed_ip='10.10.10.1', iface=self.iface)
        self.send_recv()

    def test_dhcp_1request_with_invalid_source_mac_broadcast(self):
        config = {
            'startip': '10.10.10.20',
            'endip': '10.10.10.69',
            'ip': '10.10.10.2',
            'mac': "ca:fe:ca:fe:ca:fe",
            'subnet': '255.255.255.0',
            'broadcast': '10.10.10.255',
            'router': '10.10.10.1'
        }
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip='10.10.10.1', iface=self.iface)
        cip, sip, mac, _ = self.dhcp.only_discover(mac='ff:ff:ff:ff:ff:ff')
        assert_equal(cip, None)
        log_test.info(
            'ONOS dhcp server rejected client discover with invalid source mac as expected'
        )

    def test_dhcp_1request_with_invalid_source_mac_multicast(self):
        config = {
            'startip': '10.10.10.20',
            'endip': '10.10.10.69',
            'ip': '10.10.10.2',
            'mac': "ca:fe:ca:fe:ca:fe",
            'subnet': '255.255.255.0',
            'broadcast': '10.10.10.255',
            'router': '10.10.10.1'
        }
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip='10.10.10.1', iface=self.iface)
        cip, sip, mac, _ = self.dhcp.only_discover(mac='01:80:c2:91:02:e4')
        assert_equal(cip, None)
        log_test.info(
            'ONOS dhcp server rejected client discover with invalid source mac as expected'
        )

    def test_dhcp_1request_with_invalid_source_mac_zero(self):
        config = {
            'startip': '10.10.10.20',
            'endip': '10.10.10.69',
            'ip': '10.10.10.2',
            'mac': "ca:fe:ca:fe:ca:fe",
            'subnet': '255.255.255.0',
            'broadcast': '10.10.10.255',
            'router': '10.10.10.1'
        }
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip='10.10.10.1', iface=self.iface)
        cip, sip, mac, _ = self.dhcp.only_discover(mac='00:00:00:00:00:00')
        assert_equal(cip, None)
        log_test.info(
            'ONOS dhcp server rejected client discover with invalid source mac as expected'
        )

    def test_dhcp_Nrequest(self, requests=10):
        config = {
            'startip': '192.168.1.20',
            'endip': '192.168.1.69',
            'ip': '192.168.1.2',
            'mac': "ca:fe:ca:fe:cc:fe",
            'subnet': '255.255.255.0',
            'broadcast': '192.168.1.255',
            'router': '192.168.1.1'
        }
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip='192.168.1.1', iface=self.iface)
        ip_map = {}
        for i in range(requests):
            cip, sip = self.send_recv(update_seed=True)
            if ip_map.has_key(cip):
                log_test.info('IP %s given out multiple times' % cip)
                assert_equal(False, ip_map.has_key(cip))
            ip_map[cip] = sip

    def test_dhcp_1release(self):
        config = {
            'startip': '10.10.100.20',
            'endip': '10.10.100.230',
            'ip': '10.10.100.2',
            'mac': "ca:fe:ca:fe:8a:fe",
            'subnet': '255.255.255.0',
            'broadcast': '10.10.100.255',
            'router': '10.10.100.1'
        }
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip='10.10.100.10', iface=self.iface)
        cip, sip = self.send_recv()
        log_test.info('Releasing ip %s to server %s' % (cip, sip))
        assert_equal(self.dhcp.release(cip), True)
        log_test.info('Triggering DHCP discover again after release')
        cip2, sip2 = self.send_recv(update_seed=True)
        log_test.info('Verifying released IP was given back on rediscover')
        assert_equal(cip, cip2)
        log_test.info('Test done. Releasing ip %s to server %s' % (cip2, sip2))
        assert_equal(self.dhcp.release(cip2), True)

    def test_dhcp_Nrelease(self):
        config = {
            'startip': '192.170.1.20',
            'endip': '192.170.1.230',
            'ip': '192.170.1.2',
            'mac': "ca:fe:ca:fe:9a:fe",
            'subnet': '255.255.255.0',
            'broadcast': '192.170.1.255',
            'router': '192.170.1.1'
        }
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip='192.170.1.10', iface=self.iface)
        ip_map = {}
        for i in range(10):
            cip, sip = self.send_recv(update_seed=True)
            if ip_map.has_key(cip):
                log_test.info('IP %s given out multiple times' % cip)
                assert_equal(False, ip_map.has_key(cip))
            ip_map[cip] = sip

        for ip in ip_map.keys():
            log_test.info('Releasing IP %s' % ip)
            assert_equal(self.dhcp.release(ip), True)

        ip_map2 = {}
        log_test.info('Triggering DHCP discover again after release')
        for i in range(len(ip_map.keys())):
            cip, sip = self.send_recv(update_seed=True)
            ip_map2[cip] = sip

        log_test.info('Verifying released IPs were given back on rediscover')
        if ip_map != ip_map2:
            log_test.info('Map before release %s' % ip_map)
            log_test.info('Map after release %s' % ip_map2)
        assert_equal(ip_map, ip_map2)

    def test_dhcp_starvation_positive_scenario(self):
        config = {
            'startip': '193.170.1.20',
            'endip': '193.170.1.69',
            'ip': '193.170.1.2',
            'mac': "ca:fe:c2:fe:cc:fe",
            'subnet': '255.255.255.0',
            'broadcast': '192.168.1.255',
            'router': '192.168.1.1'
        }
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip='192.169.1.1', iface=self.iface)
        ip_map = {}
        for i in range(10):
            cip, sip = self.send_recv(update_seed=True)
            if ip_map.has_key(cip):
                log_test.info('IP %s given out multiple times' % cip)
                assert_equal(False, ip_map.has_key(cip))
            ip_map[cip] = sip

    def test_dhcp_starvation_negative_scenario(self):
        config = {
            'startip': '182.17.0.20',
            'endip': '182.17.0.69',
            'ip': '182.17.0.2',
            'mac': "ca:fe:c3:fe:ca:fe",
            'subnet': '255.255.255.0',
            'broadcast': '182.17.0.255',
            'router': '182.17.0.1'
        }
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip='182.17.0.1', iface=self.iface)
        log_test.info('Verifying passitive case')
        for x in xrange(50):
            mac = RandMAC()._fix()
            self.send_recv(mac=mac)
        log_test.info('Verifying negative case')
        cip, sip = self.send_recv(update_seed=True, validate=False)
        assert_equal(cip, None)
        assert_equal(sip, None)

    def test_dhcp_same_client_multiple_discover(self):
        config = {
            'startip': '10.10.10.20',
            'endip': '10.10.10.69',
            'ip': '10.10.10.2',
            'mac': "ca:fe:ca:fe:ca:fe",
            'subnet': '255.255.255.0',
            'broadcast': '10.10.10.255',
            'router': '10.10.10.1'
        }
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip='10.10.10.1', iface=self.iface)
        cip, sip, mac, _ = self.dhcp.only_discover()
        log_test.info(
            'Got dhcp client IP %s from server %s for mac %s . Not going to send DHCPREQUEST.'
            % (cip, sip, mac))
        assert_not_equal(cip, None)
        log_test.info('Triggering DHCP discover again.')
        new_cip, new_sip, new_mac, _ = self.dhcp.only_discover()
        assert_equal(new_cip, cip)
        log_test.info('client got same IP as expected when sent 2nd discovery')

    def test_dhcp_same_client_multiple_request(self):
        config = {
            'startip': '10.10.10.20',
            'endip': '10.10.10.69',
            'ip': '10.10.10.2',
            'mac': "ca:fe:ca:fe:ca:fe",
            'subnet': '255.255.255.0',
            'broadcast': '10.10.10.255',
            'router': '10.10.10.1'
        }
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip='10.10.10.1', iface=self.iface)
        log_test.info('Sending DHCP discover and DHCP request.')
        cip, sip = self.send_recv()
        mac = self.dhcp.get_mac(cip)[0]
        log_test.info("Sending DHCP request again.")
        new_cip, new_sip = self.dhcp.only_request(cip, mac)
        assert_equal(new_cip, cip)
        log_test.info(
            'server offered same IP to clain for multiple requests, as expected'
        )

    def test_dhcp_client_desired_address(self):
        config = {
            'startip': '20.20.20.30',
            'endip': '20.20.20.69',
            'ip': '20.20.20.2',
            'mac': "ca:fe:ca:fe:ca:fe",
            'subnet': '255.255.255.0',
            'broadcast': '20.20.20.255',
            'router': '20.20.20.1'
        }
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip='20.20.20.50', iface=self.iface)
        cip, sip, mac, _ = self.dhcp.only_discover(desired=True)
        assert_not_equal(cip, None)
        log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
                      (cip, sip, mac))
        assert_equal(cip, self.dhcp.seed_ip)
        log_test.info(
            'ONOS dhcp server offered client requested IP %s as expected' %
            self.dhcp.seed_ip)

    #test failing, server not returns NAK when requested out of pool IP
    def test_dhcp_client_desired_address_out_of_pool(self):
        config = {
            'startip': '20.20.20.30',
            'endip': '20.20.20.69',
            'ip': '20.20.20.2',
            'mac': "ca:fe:ca:fe:ca:fe",
            'subnet': '255.255.255.0',
            'broadcast': '20.20.20.255',
            'router': '20.20.20.1'
        }
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip='20.20.20.75', iface=self.iface)
        cip, sip, mac, _ = self.dhcp.only_discover(desired=True)
        assert_not_equal(cip, None)
        log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
                      (cip, sip, mac))
        assert_not_equal(cip, self.dhcp.seed_ip)
        log_test.info(
            'server offered IP from its pool of IPs when requested out of pool IP, as expected'
        )

    def test_dhcp_server_nak_packet(self):
        config = {
            'startip': '20.20.20.30',
            'endip': '20.20.20.69',
            'ip': '20.20.20.2',
            'mac': "ca:fe:ca:fe:ca:fe",
            'subnet': '255.255.255.0',
            'broadcast': '20.20.20.255',
            'router': '20.20.20.1'
        }
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip='20.20.20.45', iface=self.iface)
        cip, sip, mac, _ = self.dhcp.only_discover()
        log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
                      (cip, sip, mac))
        assert_not_equal(cip, None)
        new_cip, new_sip = self.dhcp.only_request('20.20.20.31', mac)
        assert_equal(new_cip, None)  #Negative Test Case
        log_test.info(
            'dhcp servers sent NAK as expected when requested different IP from  same client'
        )

    #test_dhcp_lease_packet
    def test_dhcp_client_requests_specific_lease_time_in_discover(
            self, lease_time=700):
        config = {
            'startip': '20.20.20.30',
            'endip': '20.20.20.69',
            'ip': '20.20.20.2',
            'mac': "ca:fe:ca:fe:ca:fe",
            'subnet': '255.255.255.0',
            'broadcast': '20.20.20.255',
            'router': '20.20.20.1'
        }
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip='20.20.20.45', iface=self.iface)
        self.dhcp.return_option = 'lease'
        log_test.info('Sending DHCP discover with lease time of 700')
        cip, sip, mac, lval = self.dhcp.only_discover(lease_time=True,
                                                      lease_value=lease_time)
        assert_equal(lval, 700)
        log_test.info(
            'dhcp server offered IP address with client requested lease  time')

    def test_dhcp_client_request_after_reboot(self):
        config = {
            'startip': '20.20.20.30',
            'endip': '20.20.20.69',
            'ip': '20.20.20.2',
            'mac': "ca:fe:ca:fe:ca:fe",
            'subnet': '255.255.255.0',
            'broadcast': '20.20.20.255',
            'router': '20.20.20.1'
        }
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip='20.20.20.45', iface=self.iface)
        cip, sip, mac, _ = self.dhcp.only_discover()
        log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
                      (cip, sip, mac))
        assert_not_equal(cip, None)
        new_cip, new_sip = self.dhcp.only_request(cip, mac)
        log_test.info('verifying client IP after reboot')
        os.system('ifconfig ' + self.iface + ' down')
        time.sleep(5)
        os.system('ifconfig ' + self.iface + ' up')
        new_cip, new_sip = self.dhcp.only_request(cip, mac, cl_reboot=True)
        assert_equal(new_cip, cip)
        log_test.info('client got same ip after reboot, as expected')

    def test_dhcp_server_after_reboot(self):
        config = {
            'startip': '20.20.20.30',
            'endip': '20.20.20.69',
            'ip': '20.20.20.2',
            'mac': "ca:fe:ca:fe:ca:fe",
            'subnet': '255.255.255.0',
            'broadcast': '20.20.20.255',
            'router': '20.20.20.1'
        }
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip='20.20.20.45', iface=self.iface)
        cip, sip, mac, _ = self.dhcp.only_discover()
        log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
                      (cip, sip, mac))
        assert_not_equal(cip, None)
        new_cip, new_sip = self.dhcp.only_request(cip, mac)
        self.onos_ctrl.deactivate()
        new_cip1, new_sip = self.dhcp.only_request(cip, mac)
        assert_equal(new_cip1, None)
        status, _ = self.onos_ctrl.activate()
        assert_equal(status, True)
        time.sleep(3)
        new_cip2, new_sip = self.dhcp.only_request(cip, mac)
        assert_equal(new_cip2, cip)
        log_test.info('client got same ip after server reboot, as expected')

    def test_dhcp_specific_lease_time_only_in_discover_but_not_in_request_packet(
            self, lease_time=700):
        config = {
            'startip': '20.20.20.30',
            'endip': '20.20.20.69',
            'ip': '20.20.20.2',
            'mac': "ca:fe:ca:fe:ca:fe",
            'subnet': '255.255.255.0',
            'broadcast': '20.20.20.255',
            'router': '20.20.20.1'
        }
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip='20.20.20.45', iface=self.iface)
        log_test.info('Sending DHCP discover with lease time of 700')
        cip, sip, mac, _ = self.dhcp.only_discover(lease_time=True,
                                                   lease_value=lease_time)
        log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
                      (cip, sip, mac))
        assert_not_equal(cip, None)
        new_cip, new_sip, lval = self.dhcp.only_request(cip,
                                                        mac,
                                                        lease_time=True)
        assert_equal(new_cip, cip)
        assert_not_equal(lval, lease_time)  #Negative Test Case
        log_test.info(
            'client requested lease time only in discover but not in request, not seen in server ACK packet as expected'
        )

    def test_dhcp_specific_lease_time_only_in_request_but_not_in_discover_packet(
            self, lease_time=800):
        config = {
            'startip': '20.20.20.30',
            'endip': '20.20.20.69',
            'ip': '20.20.20.2',
            'mac': "ca:fe:ca:fe:ca:fe",
            'subnet': '255.255.255.0',
            'broadcast': '20.20.20.255',
            'router': '20.20.20.1'
        }
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip='20.20.20.45', iface=self.iface)
        cip, sip, mac, _ = self.dhcp.only_discover()
        log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
                      (cip, sip, mac))
        assert_not_equal(cip, None)
        new_cip, new_sip, lval = self.dhcp.only_request(cip,
                                                        mac,
                                                        lease_time=True,
                                                        lease_value=lease_time)
        assert_equal(lval, lease_time)
        log_test.info(
            'client requested lease time in request packet, seen in server ACK packet as expected'
        )

    def test_dhcp_client_renew_time(self):

        config = {
            'startip': '20.20.20.30',
            'endip': '20.20.20.69',
            'ip': '20.20.20.2',
            'mac': "ca:fe:ca:fe:ca:fe",
            'subnet': '255.255.255.0',
            'broadcast': '20.20.20.255',
            'router': '20.20.20.1'
        }
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip='20.20.20.45', iface=self.iface)
        cip, sip, mac, _ = self.dhcp.only_discover()
        log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
                      (cip, sip, mac))
        assert_not_equal(cip, None)
        new_cip, new_sip, lval = self.dhcp.only_request(cip,
                                                        mac,
                                                        renew_time=True)
        log_test.info(
            'waiting renew  time %d seconds to send next request packet' %
            lval)
        time.sleep(lval)
        latest_cip, latest_sip, lval = self.dhcp.only_request(cip,
                                                              mac,
                                                              renew_time=True)
        assert_equal(latest_cip, cip)
        log_test.info('client got same IP after renew time, as expected')

    def test_dhcp_client_rebind_time(self):

        config = {
            'startip': '20.20.20.30',
            'endip': '20.20.20.69',
            'ip': '20.20.20.2',
            'mac': "ca:fe:ca:fe:ca:fe",
            'subnet': '255.255.255.0',
            'broadcast': '20.20.20.255',
            'router': '20.20.20.1'
        }
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip='20.20.20.45', iface=self.iface)
        cip, sip, mac, _ = self.dhcp.only_discover()
        log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
                      (cip, sip, mac))
        assert_not_equal(cip, None)
        new_cip, new_sip, lval = self.dhcp.only_request(cip,
                                                        mac,
                                                        rebind_time=True)
        log_test.info(
            'waiting rebind time %d seconds to send next request packet' %
            lval)
        time.sleep(lval)
        latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac)
        assert_equal(latest_cip, cip)
        log_test.info('client got same IP after rebind time, as expected')

    def test_dhcp_client_expected_subnet_mask(self):

        config = {
            'startip': '20.20.20.30',
            'endip': '20.20.20.69',
            'ip': '20.20.20.2',
            'mac': "ca:fe:ca:fe:ca:fe",
            'subnet': '255.255.255.0',
            'broadcast': '20.20.20.255',
            'router': '20.20.20.1'
        }
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip='20.20.20.45', iface=self.iface)
        expected_subnet = '255.255.255.0'
        self.dhcp.return_option = 'subnet'
        cip, sip, mac, subnet_mask = self.dhcp.only_discover()
        assert_equal(subnet_mask, expected_subnet)
        assert_not_equal(cip, None)
        log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
                      (cip, sip, mac))
        log_test.info('seen expected subnet mask %s in dhcp offer packet' %
                      subnet_mask)

    def test_dhcp_client_sends_dhcp_request_with_wrong_subnet_mask(self):

        config = {
            'startip': '20.20.20.30',
            'endip': '20.20.20.69',
            'ip': '20.20.20.2',
            'mac': "ca:fe:ca:fe:ca:fe",
            'subnet': '255.255.255.0',
            'broadcast': '20.20.20.255',
            'router': '20.20.20.1'
        }
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip='20.20.20.45', iface=self.iface)

        cip, sip, mac, _ = self.dhcp.only_discover()
        log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
                      (cip, sip, mac))
        assert_not_equal(cip, None)
        self.dhcp.send_different_option = 'subnet'
        new_cip, new_sip = self.dhcp.only_request(cip, mac)
        assert_equal(new_cip, cip)
        log_test.info(
            "Got DHCP Ack despite of specifying wrong Subnet Mask in DHCP Request."
        )

    def test_dhcp_client_expected_router_address(self):

        config = {
            'startip': '20.20.20.30',
            'endip': '20.20.20.69',
            'ip': '20.20.20.2',
            'mac': "ca:fe:ca:fe:ca:fe",
            'subnet': '255.255.255.0',
            'broadcast': '20.20.20.255',
            'router': '20.20.20.1'
        }
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip='20.20.20.45', iface=self.iface)
        expected_router_address = '20.20.20.1'
        self.dhcp.return_option = 'router'

        cip, sip, mac, router_address_ip = self.dhcp.only_discover()
        log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
                      (cip, sip, mac))
        assert_not_equal(cip, None)
        assert_equal(expected_router_address, router_address_ip)
        log_test.info(
            'seen expected rouer address %s ip in dhcp offer packet' %
            router_address_ip)

    def test_dhcp_client_sends_dhcp_request_with_wrong_router_address(self):

        config = {
            'startip': '20.20.20.30',
            'endip': '20.20.20.69',
            'ip': '20.20.20.2',
            'mac': "ca:fe:ca:fe:ca:fe",
            'subnet': '255.255.255.0',
            'broadcast': '20.20.20.255',
            'router': '20.20.20.1'
        }
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip='20.20.20.45', iface=self.iface)

        cip, sip, mac, _ = self.dhcp.only_discover()
        log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
                      (cip, sip, mac))
        assert_not_equal(cip, None)
        self.dhcp.send_different_option = 'router'
        new_cip, new_sip = self.dhcp.only_request(cip, mac)
        assert_equal(new_cip, cip)
        log_test.info(
            "Got DHCP Ack despite of specifying wrong Router Address in DHCP Request."
        )

    def test_dhcp_client_expected_broadcast_address(self):

        config = {
            'startip': '20.20.20.30',
            'endip': '20.20.20.69',
            'ip': '20.20.20.2',
            'mac': "ca:fe:ca:fe:ca:fe",
            'subnet': '255.255.255.0',
            'broadcast': '20.20.20.255',
            'router': '20.20.20.1'
        }
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip='20.20.20.45', iface=self.iface)
        expected_broadcast_address = '20.20.20.255'
        self.dhcp.return_option = 'broadcast_address'

        cip, sip, mac, broadcast_address = self.dhcp.only_discover()
        log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
                      (cip, sip, mac))
        assert_not_equal(cip, None)
        assert_equal(expected_broadcast_address, broadcast_address)
        log_test.info(
            'seen expected broadcast address %s in dhcp offer packet' %
            broadcast_address)

    def test_dhcp_client_sends_dhcp_request_with_wrong_broadcast_address(self):

        config = {
            'startip': '20.20.20.30',
            'endip': '20.20.20.69',
            'ip': '20.20.20.2',
            'mac': "ca:fe:ca:fe:ca:fe",
            'subnet': '255.255.255.0',
            'broadcast': '20.20.20.255',
            'router': '20.20.20.1'
        }
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip='20.20.20.45', iface=self.iface)

        cip, sip, mac, _ = self.dhcp.only_discover()
        log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
                      (cip, sip, mac))
        assert_not_equal(cip, None)
        self.dhcp.send_different_option = 'broadcast_address'
        new_cip, new_sip = self.dhcp.only_request(cip, mac)
        assert_equal(new_cip, cip)
        log_test.info(
            "Got DHCP Ack despite of specifying wrong Broadcast Address in DHCP Request."
        )

    def test_dhcp_client_expected_dns_address(self):

        config = {
            'startip': '20.20.20.30',
            'endip': '20.20.20.69',
            'ip': '20.20.20.2',
            'mac': "ca:fe:ca:fe:ca:fe",
            'subnet': '255.255.255.0',
            'broadcast': '20.20.20.255',
            'router': '20.20.20.1',
            'domain': '8.8.8.8'
        }
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip='20.20.20.45', iface=self.iface)
        expected_dns_address = '8.8.8.8'
        self.dhcp.return_option = 'dns'

        cip, sip, mac, dns_address = self.dhcp.only_discover()
        assert_not_equal(cip, None)
        log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
                      (cip, sip, mac))
        assert_equal(expected_dns_address, dns_address)
        log_test.info('seen expected DNS ip address %s in dhcp offer packet' %
                      dns_address)

    def test_dhcp_client_sends_request_with_wrong_dns_address(self):

        config = {
            'startip': '20.20.20.30',
            'endip': '20.20.20.69',
            'ip': '20.20.20.2',
            'mac': "ca:fe:ca:fe:ca:fe",
            'subnet': '255.255.255.0',
            'broadcast': '20.20.20.255',
            'router': '20.20.20.1',
            'domain': '8.8.8.8'
        }
        self.onos_dhcp_table_load(config)
        self.dhcp = DHCPTest(seed_ip='20.20.20.45', iface=self.iface)

        cip, sip, mac, _ = self.dhcp.only_discover()
        assert_not_equal(cip, None)
        log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
                      (cip, sip, mac))
        self.dhcp.send_different_option = 'dns'
        new_cip, new_sip = self.dhcp.only_request(cip, mac)
        assert_equal(new_cip, cip)
        log_test.info(
            "Got DHCP Ack despite of specifying wrong DNS Address in DHCP Request."
        )

    def test_dhcp_server_transactions_per_second(self):

        for i in range(1, 4):
            self.stats()
            log_test.info("Stats for run %d", i)
            log_test.info(
                "----------------------------------------------------------------------------------"
            )
            log_test.info(
                "No. of transactions     No. of successes     No. of failures     Running Time "
            )
            log_test.info(
                "    %d                    %d                     %d                  %d"
                % (self.ip_count + self.failure_count, self.ip_count,
                   self.failure_count, self.diff))
            log_test.info(
                "----------------------------------------------------------------------------------"
            )
            log_test.info("No. of transactions per second in run %d:%f" %
                          (i, self.transaction_count))

        log_test.info("Final Statistics for total transactions")
        log_test.info(
            "----------------------------------------------------------------------------------"
        )
        log_test.info(
            "Total transactions     Total No. of successes     Total No. of failures     Running Time "
        )
        log_test.info(
            "    %d                     %d                         %d                        %d"
            % (self.transactions, self.total_success, self.total_failure,
               self.running_time))
        log_test.info(
            "----------------------------------------------------------------------------------"
        )
        log_test.info("Average no. of transactions per second: %d",
                      round(self.transactions / self.running_time, 0))

    def test_dhcp_server_consecutive_successes_per_second(self):

        for i in range(1, 4):
            self.stats(success_rate=True)
            log_test.info("Stats for run %d", i)
            log_test.info(
                "----------------------------------------------------------------------------------"
            )
            log_test.info(
                "No. of consecutive successful transactions          Running Time "
            )
            log_test.info(
                "                   %d                                   %d        "
                % (self.ip_count, self.diff))
            log_test.info(
                "----------------------------------------------------------------------------------"
            )
            log_test.info(
                "No. of successful transactions per second in run %d:%f" %
                (i, self.transaction_count))
            log_test.info(
                "----------------------------------------------------------------------------------"
            )

        log_test.info("Final Statistics for total successful transactions")
        log_test.info(
            "----------------------------------------------------------------------------------"
        )
        log_test.info(
            "Total transactions     Total No. of consecutive successes         Running Time "
        )
        log_test.info(
            "    %d                                 %d                             %d        "
            % (self.transactions, self.total_success, self.running_time))
        log_test.info(
            "----------------------------------------------------------------------------------"
        )
        log_test.info(
            "Average no. of consecutive successful transactions per second: %d",
            round(self.total_success / self.running_time, 0))
        log_test.info(
            "----------------------------------------------------------------------------------"
        )

    def test_dhcp_server_client_transactions_per_second(self):

        for i in range(1, 4):
            self.stats(only_discover=True)
            log_test.info(
                "----------------------------------------------------------------------------------"
            )
            log_test.info("Stats for run %d of sending only DHCP Discover", i)
            log_test.info(
                "----------------------------------------------------------------------------------"
            )
            log_test.info(
                "No. of transactions     No. of successes     No. of failures     Running Time "
            )
            log_test.info(
                "    %d                    %d                     %d                  %d"
                % (self.ip_count + self.failure_count, self.ip_count,
                   self.failure_count, self.diff))
            log_test.info(
                "----------------------------------------------------------------------------------"
            )
            log_test.info(
                "No. of clients per second in run %d:%f                                      "
                % (i, self.transaction_count))
            log_test.info(
                "----------------------------------------------------------------------------------"
            )
        log_test.info(
            "Final Statistics for total transactions of sending only DHCP Discover"
        )
        log_test.info(
            "----------------------------------------------------------------------------------"
        )
        log_test.info(
            "Total transactions     Total No. of successes     Total No. of failures     Running Time "
        )
        log_test.info(
            "    %d                     %d                         %d                        %d"
            % (self.transactions, self.total_success, self.total_failure,
               self.running_time))
        log_test.info(
            "----------------------------------------------------------------------------------"
        )
        log_test.info(
            "Average no. of clients per second: %d                                        ",
            round(self.transactions / self.running_time, 0))
        log_test.info(
            "----------------------------------------------------------------------------------"
        )

    def test_dhcp_server_consecutive_successful_clients_per_second(self):

        for i in range(1, 4):
            self.stats(success_rate=True, only_discover=True)
            log_test.info(
                "----------------------------------------------------------------------------------"
            )
            log_test.info("Stats for run %d for sending only DHCP Discover", i)
            log_test.info(
                "----------------------------------------------------------------------------------"
            )
            log_test.info(
                "No. of consecutive successful transactions          Running Time "
            )
            log_test.info(
                "                   %d                                   %d        "
                % (self.ip_count, self.diff))
            log_test.info(
                "----------------------------------------------------------------------------------"
            )
            log_test.info(
                "No. of consecutive successful clients per second in run %d:%f"
                % (i, self.transaction_count))
            log_test.info(
                "----------------------------------------------------------------------------------"
            )

        log_test.info("Final Statistics for total successful transactions")
        log_test.info(
            "----------------------------------------------------------------------------------"
        )
        log_test.info(
            "Total transactions     Total No. of consecutive successes         Running Time "
        )
        log_test.info(
            "    %d                                 %d                             %d        "
            % (self.transactions, self.total_success, self.running_time))
        log_test.info(
            "----------------------------------------------------------------------------------"
        )
        log_test.info(
            "Average no. of consecutive successful clients per second: %d",
            round(self.total_success / self.running_time, 0))
        log_test.info(
            "----------------------------------------------------------------------------------"
        )
Exemplo n.º 47
0
 def setUpClass(cls):
     onos_ctrl = OnosCtrl('org.onosproject.cpman')
     status, _ = onos_ctrl.activate()
Exemplo n.º 48
0
 def install_app(cls):
     OnosCtrl.uninstall_app(cls.igmp_app)
     time.sleep(2)
     OnosCtrl.install_app(cls.igmp_app_file)
     time.sleep(3)
Exemplo n.º 49
0
 def onos_load_config(self, app, config):
     status, code = OnosCtrl.config(config)
     if status is False:
        log.info('JSON config request for app %s returned status %d' %(app, code))
        assert_equal(status, True)
     time.sleep(2)
Exemplo n.º 50
0
 def setUp(self):
     super(eap_auth_exchange, self).setUp()
     self.onos_ctrl = OnosCtrl(self.app)
     self.onos_aaa_config()