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_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_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 sendFlow(self, deviceId, flowJson): """ Description: Sends a single flow to the specified device. This function exists so you can bypass the addFLow driver and send your own custom flow. Required: * The flow in json * the device id to add the flow to Returns: True for successful requests False for error on requests; """ url = self.cfg_url + str(deviceId) response = requests.post(url, auth = self.auth, data = json.dumps(flowJson) ) if response.ok: if response.status_code in [200, 201]: log_test.info('Successfully POSTED flow for device %s' %str(deviceId)) return True else: log_test.info('Post flow for device %s failed with status %d' %(str(deviceId), response.status_code)) return False else: log_test.error('Flow post request returned with status %d' %response.status_code) return False
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 verify_proxyarp(*r): ingress, hostmac, hostip = r[0], r[1], r[2] def mac_recv_task(): def recv_cb(pkt): log_test.info('Arp Reply seen with source Mac is %s' % (pkt[ARP].hwsrc)) success_dir[current_thread().name] = True replied_hosts.append(hostip) sniff(count=1, timeout=5, lfilter=lambda p: ARP in p and p[ARP].op == 2 and p[ARP]. psrc == hostip, prn=recv_cb, iface=self.port_map[ingress]) t = threading.Thread(target=mac_recv_task) t.start() pkt = (Ether(dst='ff:ff:ff:ff:ff:ff') / ARP(op=1, pdst=hostip)) log_test.info( 'sending arp request for dest ip %s on interface %s' % (hostip, self.port_map[ingress])) sendp(pkt, count=10, iface=self.port_map[ingress]) t.join()
def eap_tls_packets_field_value_replace(self, invalid_field_name=None): log_test.info('Changing invalid field values in tls auth packets') if invalid_field_name == 'eapolTlsVersion': global EAPOL_VERSION EAPOL_VERSION = 1 log_test.info( 'Changing invalid field values in tls auth packets====== version changing' ) if invalid_field_name == 'eapolTlsType': global EAP_TYPE_TLS EAP_TYPE_TLS = 13 log_test.info( 'Changing invalid field values in tls auth packets====== version changing' ) if invalid_field_name == 'eapolTypeID': global EAP_TYPE_ID EAP_TYPE_ID = 1 log_test.info( 'Changing invalid field values in tls auth packets====== version changing' ) if invalid_field_name == 'eapolResponse': global EAP_RESPONSE EAP_RESPONSE = 2 log_test.info( 'Changing invalid field values in tls auth packets====== version changing' )
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 _eapIdReq(self): log_test.info('Inside EAP ID Req for interface %s' % (self.intf)) def eapol_cb(pkt): log_test.info( 'Got EAPOL packet with type id and code request for interface %s' % (self.intf)) log_test.info( 'Interface: %s, Packet code: %d, type: %d, id: %d' % (self.intf, pkt[EAP].code, pkt[EAP].type, pkt[EAP].id)) log_test.info( "Send EAP Response with identity %s over interface %s" % (USER, self.intf)) if self.id_mismatch_in_identifier_response_packet: log_test.info( '\nSending invalid id field in EAP Identity Response packet over interface %s' % (self.intf)) self.eapol_id_req(pkt[EAP].id + 10, USER) else: self.eapol_id_req(pkt[EAP].id, USER) r = self.eapol_scapy_recv( cb=eapol_cb, lfilter=lambda pkt: EAP in pkt and pkt[ EAP].type == EAP.TYPE_ID and pkt[EAP].code == EAP.REQUEST) if len(r) > 0: self.nextEvent = self.tlsEventTable.EVT_EAP_TLS_HELLO_REQ else: self.tlsFail() return r
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 subscriberDelete(self, account_num, s_tag=None, c_tag=None, subId='', voltId=''): result = self.restApi.ApiGet('VOLT_SUBSCRIBER') assert_not_equal(result, None) result = result['items'] if not subId: #get the subscriber id first subInfo, subId = self.getSubscriberId(result, account_num) assert_not_equal(subId, '0') else: subInfo, currentSubId = self.getSubscriberId(result, account_num) assert_not_equal(currentSubId, '0') #assert_equal(subId, currentSubId) subId = self.getFieldValueFromDict(subInfo, 'id') if not voltId: #get the volt id for the subscriber result = self.restApi.ApiGet('VOLT_TENANT') assert_not_equal(result, None) result = result['items'] voltId = self.getVoltId(result, subInfo, s_tag=s_tag, c_tag=c_tag) assert_not_equal(voltId, None) log.info('Deleting VOLT Tenant ID %s for subscriber %s' % (voltId, subId)) status = self.restApi.ApiChameleonDelete('VOLT_TENANT', voltId) assert_equal(status, True) log.info('Deleting subscriber ID %s for account num %s' % (subId, str(account_num))) status = self.restApi.ApiChameleonDelete('VOLT_SUBSCRIBER', subId) assert_equal(status, True)
def adding_acl_rule(self, ipv4Prefix, srcIp, dstIp, ipProto='null', dstTpPort='null', action='include', controller=None): '''This function is generating ACL json file and post to ONOS for creating a ACL rule''' if ipv4Prefix is 'v4': acl_dict = {} if srcIp and dstIp and action: acl_dict['srcIp'] = '{}'.format(srcIp) acl_dict['dstIp'] = '{}'.format(dstIp) acl_dict['action'] = '{}'.format(action) if ipProto is not 'null': acl_dict['ipProto'] = '{}'.format(ipProto) if dstTpPort is not 'null': acl_dict['dstTpPort'] = '{}'.format(dstTpPort) json_data = json.dumps(acl_dict) if controller is None: # if controller ip is not passed, it will default controller ip resp = requests.post(self.add_acl_rule_url, auth=self.auth, data=json_data) else: add_acl_rule_url = 'http://%s:8181/onos/v1/acl/rules' % ( controller) log_test.info('add_acl_rule_acl url is %s' % add_acl_rule_url) resp = requests.post(add_acl_rule_url, auth=self.auth, data=json_data) return resp.ok, resp.status_code
def test_proxyarp_removing_host(self, hosts=3): ports_map, egress_map, hosts_config = self.proxyarp_config(hosts=hosts) ingress = hosts + 1 for hostip, hostmac in hosts_config: self.proxyarp_arpreply_verify(ingress, hostip, hostmac, PositiveTest=True) time.sleep(1) host_mac = hosts_config[0][1] log_test.info('removing host entry %s' % host_mac) self.cliEnter() hostentries = json.loads(self.cli.hosts(jsonFormat=True)) for host in hostentries: res = host_mac.upper() in host.values() if res: break assert_equal(res, True) hostid = host_mac + '/' + 'None' delete_host = self.cli.host_remove(hostid) hostentries = json.loads(self.cli.hosts(jsonFormat=True)) for host in hostentries: res = host_mac.upper() in host.values() if res: break assert_equal(res, False) self.proxyarp_arpreply_verify(ingress, hosts_config[0][0], host_mac, PositiveTest=False) time.sleep(1) self.cliExit()
def vrouter_port_send_recv(self, ingress, egress, dst_mac, dst_ip, positive_test = True): src_mac = '00:00:00:00:00:02' src_ip = '1.1.1.1' self.success = False if positive_test else True timeout = 10 if positive_test else 1 count = 2 if positive_test else 1 self.start_sending = True def recv_task(): def recv_cb(pkt): log_test.info('Pkt seen with ingress ip %s, egress ip %s' %(pkt[IP].src, pkt[IP].dst)) self.success = True if positive_test else False sniff(count=count, timeout=timeout, lfilter = lambda p: IP in p and p[IP].dst == dst_ip and p[IP].src == src_ip, prn = recv_cb, iface = self.port_map[ingress]) self.start_sending = False t = threading.Thread(target = recv_task) t.start() L2 = Ether(src = src_mac, dst = dst_mac) L3 = IP(src = src_ip, dst = dst_ip) pkt = L2/L3 log_test.info('Sending a packet with dst ip %s, dst mac %s on port %s to verify if flows are correct' % (dst_ip, dst_mac, self.port_map[egress])) while self.start_sending is True: sendp(pkt, count=50, iface = self.port_map[egress]) t.join() assert_equal(self.success, True)
def test_proxyarp_app_with_disabling_and_re_enabling(self, hosts=3): ports_map, egress_map, hosts_config = self.proxyarp_config(hosts=hosts) ingress = hosts + 1 for hostip, hostmac in hosts_config: self.proxyarp_arpreply_verify(ingress, hostip, hostmac, PositiveTest=True) time.sleep(1) log_test.info( 'Deactivating proxyarp app and expecting not to get arp reply from ONOS' ) self.proxyarp_activate(deactivate=True) for hostip, hostmac in hosts_config: self.proxyarp_arpreply_verify(ingress, hostip, hostmac, PositiveTest=False) time.sleep(1) log_test.info( 'activating proxyarp app and expecting to get arp reply from ONOS' ) self.proxyarp_activate(deactivate=False) for hostip, hostmac in hosts_config: self.proxyarp_arpreply_verify(ingress, hostip, hostmac, PositiveTest=True) time.sleep(1)
def test_proxyarp_nonexisting_host(self, hosts=1): _, _, hosts_config = self.proxyarp_config(hosts=hosts) ingress = hosts + 2 for host, mac in hosts_config: self.proxyarp_arpreply_verify(ingress, host, mac, PositiveTest=True) new_host = hosts_config[-1][0].split('.') new_host[2] = str(int(new_host[2]) + 1) new_host = '.'.join(new_host) new_mac = RandMAC()._fix() log_test.info('verifying arp reply for host ip %s on interface %s' % (new_host, self.port_map[ingress])) res = srp1(Ether(dst='ff:ff:ff:ff:ff:ff') / ARP(op=1, pdst=new_host), timeout=2, iface=self.port_map[ingress]) assert_equal(res, None) log_test.info( 'arp reply not seen for host ip %s on interface %s as expected' % (new_host, self.port_map[ingress])) hosts = hosts + 1 _, _, hosts_config = self.proxyarp_config(hosts=hosts) for host in hosts_config: if host[0] == new_host: new_mac = host[1] self.proxyarp_arpreply_verify(ingress, new_host, new_mac, PositiveTest=True)
def proxyarp_arpreply_verify(self, ingress, hostip, hostmac, PositiveTest=True): log_test.info( 'verifying arp reply for host ip %s host mac %s on interface %s' % (hostip, hostmac, self.port_map[ingress])) self.success = False def recv_task(): def recv_cb(pkt): log_test.info('Arp Reply seen with source Mac is %s' % (pkt[ARP].hwsrc)) self.success = True if PositiveTest == True else False sniff(count=1, timeout=2, lfilter=lambda p: ARP in p and p[ARP].op == 2 and p[ARP]. hwsrc == hostmac, prn=recv_cb, iface=self.port_map[ingress]) t = threading.Thread(target=recv_task) t.start() pkt = (Ether(dst='ff:ff:ff:ff:ff:ff') / ARP(op=1, pdst=hostip)) log_test.info('sending arp request for dest ip %s on interface %s' % (hostip, self.port_map[ingress])) sendp(pkt, count=10, iface=self.port_map[ingress]) t.join() if PositiveTest: assert_equal(self.success, True) else: assert_equal(self.success, False)
def eap_invalid_tls_packets_info(self, invalid_field_name=None, invalid_field_value=None): log_test.info('Changing invalid field values in tls auth packets') if invalid_field_name == 'eapolTlsVersion': global EAPOL_VERSION log_test.info( 'Changing invalid field values in tls auth packets====== version changing' ) EAPOL_VERSION = invalid_field_value if invalid_field_name == 'eapolTlsType': global EAP_TYPE_TLS log_test.info( 'Changing invalid field values in tls auth packets====== EAP TYPE TLS changing' ) EAP_TYPE_TLS = invalid_field_value if invalid_field_name == 'eapolTypeID': global EAP_TYPE_ID log_test.info( 'Changing invalid field values in tls auth packets====== EAP TYPE TLS changing' ) EAP_TYPE_ID = invalid_field_value if invalid_field_name == 'eapolResponse': global EAP_RESPONSE log_test.info( 'Changing invalid field values in tls auth packets====== EAP TYPE TLS changing' ) EAP_RESPONSE = invalid_field_value
def tlsFail(self): ##Force a failure log_test.info('entering into testFail function for interface %s' % self.intf) self.nextEvent = self.tlsEventTable.EVT_EAP_TLS_FINISHED self.nextState = self.tlsStateTable.ST_EAP_TLS_FINISHED self.failTest = True
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_vrouter_ipv6_with_5_routes_onos_restart_without_config(self): res = self.__vrouter_network_verify(5, peers=1) assert_equal(res, True) log_test.info( 'verifying vrouter traffic after ONOS restart without config retain' ) cord_test_onos_restart() self.vrouter_traffic_verify(positive_test=False)
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)
def get_health(self): if self.ip is None: return True cmd = 'ping -c 1 {}'.format(self.ip) log.info('Pinging ONBOARDED SERVICE %s at IP %s' %(self.name, self.ip)) st, _ = self.run_cmd_compute(cmd) log.info('ONBOARDED SERVICE %s at IP %s is %s' %(self.name, self.ip, 'reachable' if st == True else 'unreachable')) return st
def collectd_agent_metrics(cls, controller=None, auth=None, url=None): '''This function is getting rules from ONOS with json format''' if url: resp = requests.get(url, auth=auth) log.info( 'Collectd agent has provided metrics via ONOS controller, url = %s \nand status = %s' % (url, resp.json())) return resp
def test_vrouter_ipv6_with_5_routes_quagga_restart_with_config(self): res = self.__vrouter_network_verify(5, peers=1) assert_equal(res, True) log_test.info( 'verifying vrouter traffic after Quagga restart with config retain' ) #cord_test_quagga_restart() self.start_quagga(networks=5) self.vrouter_traffic_verify(positive_test=True)
def proxyarp_host_unload(cls): index = 1 for host, _ in cls.hosts_list: iface = cls.port_map[index] index += 1 config_cmds = ('ifconfig {} 0'.format(iface), ) for cmd in config_cmds: log_test.info('host unload command %s' % cmd) os.system(cmd)
def test_vrouter_ipv6_with_5_routes_quagga_stop_and_start(self): res = self.__vrouter_network_verify(5, peers=1) assert_equal(res, True) log_test.info( 'verifying vrouter traffic after Quagga stop and start again') cord_test_quagga_stop() self.vrouter_traffic_verify(positive_test=False) self.start_quagga(networks=5) self.vrouter_traffic_verify(positive_test=True)
def collectd_agent_metrics(cls, controller=None, auth=None, url=None): '''This function is getting a rules from ONOS with json formate''' if url: resp = requests.get(url, auth=auth) log.info( 'CollectD agent has provided metrics via ONOS controller, \nurl = %s \nand stats = %s \nResponse = %s ' % (url, resp.json(), resp.ok)) assert_equal(resp.ok, True) return resp
def get_acl_rules(self, controller=None): '''This function is getting a ACL rules from ONOS with json formate''' if controller is None: resp = requests.get(self.add_acl_rule_url, auth=self.auth) else: add_acl_rule_url = 'http://%s:8181/onos/v1/acl/rules' % ( controller) log_test.info('get_acl_rule_url is %s' % add_acl_rule_url) resp = requests.get(add_acl_rule_url, auth=self.auth) return resp
def collectd_sample(df): cmd = 'sudo /etc/init.d/collectd start' output = subprocess.check_output(cmd, shell=True) if 'Starting statistics collectio' in output: log.info('Collectd is installed properly') pass else: log.info('Collectd is not installed properly') assert_equal(False, True) df.callback(0)