Skip to content

Instantly share code, notes, and snippets.

@bunlongheng
Created September 12, 2016 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bunlongheng/38e6b935827510c370302ea0c1bc9370 to your computer and use it in GitHub Desktop.
Save bunlongheng/38e6b935827510c370302ea0c1bc9370 to your computer and use it in GitHub Desktop.
#! /usr/bin/env python
import ipaddress
import netaddr
import requests
import sys
class MDU_SSC(TestCase):
'''
Create accounts of different types on SSC, Bring up tunnel on guest/private vlan's in accounts and pass traffic through all subscribers
'''
__author__ = 'Bunlong'
def setUp(self):
global TunnelSrcIp,Tunnel2SrcIp, TunnelDstIp, subMac,subMac2, p_vlan, apMac,apMac2,httpSrvIp, kafkaSrvIp, kafkaSrvPort,xpcSrvIp,num_accounts
global Tunnel1SrcIp, Tunnel2SrcIp,Tunnel3SrcIp,Tunnel4SrcIp, Tunnel1Mac, Tunnel2Mac,Tunnel3Mac,Tunnel4Mac,sscSrvIp,httpClSrvPort,p_vlan2,num_aps
global cpe_mac, Tunnel1Mac, Tunnel2Mac_no_colons,account_id,homeprofile,hns_id,dnsDummyServer,reserved_ip,AccessInterface,num_subs,vlan_per_tunnel
AccessInterface = ClientSim.P1['port']
TunnelSrcIp = ClientSim.P1['ip_address']
tunnel_subnet = ipaddress.ip_network(unicode(WAG.tunnelSubnet))
self.assertTrue(
WAG.setLocalConfig(['ip route %s %s'%(WAG.tunnelSubnet, ClientSim.P1['ip_address'])]),
msg='Configure a route for the tunnels')
tunnels_ip_list = [str(ip) for ip in tunnel_subnet.hosts()]
Tunnel1SrcIp = tunnels_ip_list[0]
Tunnel2SrcIp = tunnels_ip_list[1]
Tunnel3SrcIp = tunnels_ip_list[2]
Tunnel4SrcIp = tunnels_ip_list[3]
TunnelDstIp = WAG.P1['ip_address']
httpSrvIp = WAG.P2['ip_address']
ap_mac_list = incrMac(suite_params.ApMac,count=4)
Tunnel1Mac = ap_mac_list[0]
Tunnel2Mac = ap_mac_list[1]
Tunnel3Mac = ap_mac_list[2]
Tunnel4Mac = ap_mac_list[3]
account_id=suite_params.ssc_account
dnsDummyServer = "6.6.6.6"
WAG.setLocalConfig(['ip route %s/32 %s'%(dnsDummyServer,ClientSim.P2['ip_address'])])
httpSrvIp = WAG.P2['ip_address']
xpcSrvIp = ClientSim.P2['ip_address']
sscSrvIp=SSC.P2['ip_address']
httpClSrvPort=suite_params.sscServerPort
kafkaSrvIp = ClientSim.P2['ip_address']
kafkaSrvPort = suite_params.KafkaServerPort
subMac = suite_params.SubMac
subMac2=incrMac(subMac)[0]
p_vlan = suite_params.SubVLAN
g_vlan=(p_vlan+1)
apMac = suite_params.ApMac
num_accounts=suite_params.NumberofAccountTypes
num_cpes_per_acct=suite_params.NumberofCpePerType
vlan_per_tunnel=suite_params.NumberVlansperAp
Tunnel1Mac =''.join(str(e) for e in Tunnel1Mac.split(':'))
Tunnel2Mac_no_colons=''.join(str(e) for e in Tunnel2Mac.split(':'))
reserved_ip=incrIp(suite_params.DhcpServerIp, step=12)[0]
# sys.exit()
WAG.clearTunnels()
WAG.resetCounters()
tunnel_mac_list=incrMac(suite_params.ApMac,count=num_cpes_per_acct)
for i in range(1,num_accounts+1):
acct_id=account_id+i
self.assertTrue(POST(sscSrvIp,'/vse/account','{"account_id":%s,"email_address":"%s@benu.com","password":"benu123","account_type":"customer","name_prefix":"","first_name":"Open","middle_names":"","last_name":"Test","name_suffix":"","non_person_name":false,"DBA":"","display_name":"OpenTest","address1":"11 Peterborough Street","address2":"","address3":"","city":"Boston","state":"MA","postal_code":"02115","nation_code":"USA","phone1":"723487432","phone2":"","phone3":"","time_zone_offset_from_utc":-5,"customer_type":"%s","longitude":-71.0957612,"latitude":42.3442383,"altitude":0}'%(acct_id,acct_id,i),server_port=httpClSrvPort,status=200),msg="Create Account %s on SSC"%(acct_id))
for i in (tunnel_mac_list):
cpe_mac = TunnelMac_no_colons=''.join(str(e) for e in i.split(':'))
self.assertTrue(POST(sscSrvIp,'/vse/vcpe','{"cpe_mac":"%s","bandwidth_max_up":350000000,"bandwidth_max_down":450000000,"filter_icmp_inbound":false,"dmz_enabled":false,"dmz_host":"192.168.1.1","vlan_id":3,"dns":[],"xdns_mode":0,"cfprofileid":11111,"stub_response":"0","acl_mode":0,"portal_url":"","fullbandwidth_max_up":1000000,"fullbandwidth_max_down":2001000,"fullbandwidth_guaranty_up":300000,"fullbandwidth_guaranty_down":400000,"account_id":%s,"location_id":2,"network_count":3,"group_name":"test_group","vse_id":20,"firewall_enabled":false}'%(TunnelMac_no_colons,acct_id),server_port=httpClSrvPort,status=200),msg="Configure CPE %s on Account %s"%(TunnelMac_no_colons,acct_id))
#lan
self.assertTrue(PUT(sscSrvIp,'/vse/vcpe/%s/vlan/%s/lan'%(cpe_mac,p_vlan),'{"ip_address":"%s","netmask":"%s","upnp_enabled":true,"domain":"lan","dhcp_server":{"pool_start":%s,"max_clients":%s,"dhcp_lease_length":86400,"dns":["8.8.8.8","8.8.4.4"],"mac_binding":[]}}'%(suite_params.DhcpServerIp,suite_params.DhcpSubnet,suite_params.Pool_Start,suite_params.MaxClients),server_port=httpClSrvPort,status=200),msg="Map lan details of %s to CPE's %s"%(p_vlan,cpe_mac))
self.assertTrue(PUT(sscSrvIp,'/vse/vcpe/%s/vlan/%s/lan'%(cpe_mac,g_vlan),'{"ip_address":"%s","netmask":"%s","upnp_enabled":true,"domain":"lan","dhcp_server":{"pool_start":%s,"max_clients":%s,"dhcp_lease_length":86400,"dns":["8.8.8.8","8.8.4.4"],"mac_binding":[]}}'%(suite_params.DhcpServerIp,suite_params.DhcpSubnet,suite_params.Pool_Start,suite_params.MaxClients),server_port=httpClSrvPort,status=200),msg="Map lan details of %s to CPE's %s"%(g_vlan,cpe_mac))
# acl
self.assertTrue(PUT(sscSrvIp,'/vse/vcpe/%s/vlan/%s/acl'%(cpe_mac,p_vlan),'{"acl_mode":0,"portal_url":""}'%(),server_port=httpClSrvPort,status=200),msg="Map ACL details of %s to CPE's %s"%(p_vlan,cpe_mac))
self.assertTrue(PUT(sscSrvIp,'/vse/vcpe/%s/vlan/%s/acl'%(cpe_mac,g_vlan),'{"acl_mode":2,"portal_url":"http://www.captiveportal.com"}'%(),server_port=httpClSrvPort,status=200),msg="Map ACL details of %s to CPE's %s"%(g_vlan,cpe_mac))
#bandwidth
self.assertTrue(PUT(sscSrvIp,'/vse/vcpe/%s/vlan/%s/bandwidth'%(cpe_mac,p_vlan),
'{"fullbandwidth_max_up":128000,"fullbandwidth_max_down":128000,"fullbandwidth_guaranty_up":128000,"fullbandwidth_guaranty_down":128000}'%(),server_port=httpClSrvPort,status=200),msg="Map Bandwidth details of %s to CPE's %s"%(p_vlan,cpe_mac))
self.assertTrue(PUT(sscSrvIp,'/vse/vcpe/%s/vlan/%s/bandwidth'%(cpe_mac,g_vlan),
'{"fullbandwidth_max_up":128000,"fullbandwidth_max_down":128000,"fullbandwidth_guaranty_up":128000,"fullbandwidth_guaranty_down":128000}'%(),server_port=httpClSrvPort,status=200),msg="Map Bandwidth details of %s to CPE's %s"%(g_vlan,cpe_mac))
#devicebandwidth
self.assertTrue(PUT(sscSrvIp,'/vse/vcpe/%s/vlan/%s/devicebandwidth'%(cpe_mac,p_vlan),
'{"bandwidth_max_up":128000,"bandwidth_max_down":128000}'%(),server_port=httpClSrvPort,status=200),msg="Map Device Bandwidth details of %s to CPE's %s"%(p_vlan,cpe_mac))
self.assertTrue(PUT(sscSrvIp,'/vse/vcpe/%s/vlan/%s/devicebandwidth'%(cpe_mac,g_vlan),
'{"bandwidth_max_up":128000,"bandwidth_max_down":128000}'%(),server_port=httpClSrvPort,status=200),msg="Map Device Bandwidth details of %s to CPE's %s"%(g_vlan,cpe_mac))
#site-vpn
self.assertTrue(PUT(sscSrvIp,'/vse/vcpe/%s/vlan/%s/site_vpn'%(cpe_mac,p_vlan),
'{"bandwidth_max_up":128000,"bandwidth_max_down":128000}'%(),server_port=httpClSrvPort,status=200),msg="Map Site VPN details of %s to CPE's %s"%(p_vlan,cpe_mac))
#cpe_name
self.assertTrue(PUT(sscSrvIp,'/vse/vcpe/%s/cpe_name'%(cpe_mac),
'{"cpe_name":"fake"}'%(),server_port=httpClSrvPort,status=200),msg="Map CPE Name to CPE's %s"%(cpe_mac))
#debug
# print TunnelMac_no_colons
# sys.exit()
tunnel_mac_list=incrMac(tunnel_mac_list[-1],count=num_cpes_per_acct)
num_aps=suite_params.NumberofAccountTypes*suite_params.NumberofCpePerType
num_subs=(num_aps*suite_params.NumberVlansperAp*suite_params.NumberofSubsperVlan)
# Configure AP group
ClientSim.configure_AP_group(
number = num_aps,
base_address = Tunnel1SrcIp,
tunnel_endpoint = TunnelDstIp,
mac_address = Tunnel1Mac,
device_type = 'belair',
vlan_id = suite_params.SubVlan,
setup_rate = suite_params.TunnelSetupRate,
tunnels_per_ap=suite_params.NumberVlansperAp,
increment_vlan='per-device')
# Configure subscriber group
ClientSim.configure_sub_group(
number = (num_aps*suite_params.NumberVlansperAp*suite_params.NumberofSubsperVlan),
subs_mac = suite_params.SubMac,
tear_down_rate = suite_params.SubscriberRampDownRate,
setup_rate = suite_params.SubscriberSetupRate)
def AttachUE(self):
# Configure Access and network interfaces on clientsim
ClientSim.configure_interface(access_name= AccessInterface, network_name = ClientSim.P2['port'],virtual_switch_enabled=True)
ClientSim.stop_sub_group()
ClientSim.start_sub_group()
log.info("Waiting %s seconds to bring all the subscribers up"%((num_subs/suite_params.SubscriberSetupRate)+ 30))
time.sleep((num_subs/suite_params.SubscriberSetupRate)+ 30)
self.assertTrue(
WAG.verifyCounters(
command='show wag tunnels summary',
counters = [
('Dynamically added', num_aps),
('Home', num_aps)]),
msg='Verify the tunnel summary information')
self.assertTrue(
WAG.verifyCounters(
command='show wag subscribers summary',
counters = [
('Home subscribers', num_subs),
('Current subscribers', num_subs)]),
msg='Verify the subscriber summary information')
self.assertEqual(int(WAG.run('show bef wag subscribers | grep AUTH | count')), num_subs,
msg='Verify all the subscribers with AUTH state in fast-path')
def StartTraffic(self):
# Configure UDP traffic
ClientSim.configure_UDP(
source_port = suite_params.UDP_sport,
destination_port = suite_params.UDP_dport,
destination_ip = ClientSim.P2['ip_address'],
packet_size = suite_params.UDP_PktSize,
traffic_rate = suite_params.UDP_traffic_rate,
)
ClientSim.configure_traffic_sink(server_type='udp', port = suite_params.UDP_dport)
ClientSim.start_traffic('UDP')
log.info("Waiting 10 seconds to send traffic")
time.sleep(10)
log.info("Press letter c to stop the traffic")
pdb.set_trace()
def tearDown(self):
#stopNotificationCapture(kafkaServerIp=kafkaSrvIp)
ClientSim.stop_sub_group()
ClientSim.stop_traffic('UDP')
for j in range(1,num_accounts+1):
account=account_id+ j
self.assertTrue(DELETE(sscSrvIp,'/vse/account/%s'%(account),server_port=httpClSrvPort,status=200),msg="Delete Account %s on SSC"%(account))
tunnel_mac_list=incrMac(suite_params.ApMac,count=num_aps)
for i in (tunnel_mac_list):
TunnelMac_no_colons=''.join(str(e) for e in i.split(':'))
self.assertTrue(DELETE(sscSrvIp,'/vse/vcpe/%s'%(TunnelMac_no_colons),server_port=httpClSrvPort,status=200),msg="Delete CPE %s "%(TunnelMac_no_colons))
Keywords = ['all','MBN','SSC', 'MBN_SSC']
Topology = ['MDU_SSC']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment