Adding new DHCP tests
diff --git a/src/test/dhcp/dhcpTest.py b/src/test/dhcp/dhcpTest.py
index b5f5da3..cc7b0e0 100644
--- a/src/test/dhcp/dhcpTest.py
+++ b/src/test/dhcp/dhcpTest.py
@@ -342,7 +342,7 @@
os.system('ifconfig '+iface+' up')
log.info('Client is up now.')
- new_cip, new_sip = self.dhcp.only_request(cip, mac)
+ 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)
@@ -406,6 +406,144 @@
assert_equal(new_cip,None) #Neagtive Test Case
+ def test_dhcp_specific_lease_packet(self, iface = 'veth0'):
+ ''' Client sends DHCP Discover packet for particular lease time.'''
+ 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 = 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, iface = 'veth0'):
+ ''' Client checks lease time is 600 secs/10 mins or not.'''
+ 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 = 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, iface = 'veth0'):
+
+ 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 = 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, iface = 'veth0'):
+
+ 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 = 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) )
+
+ 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.")
diff --git a/src/test/utils/DHCP.py b/src/test/utils/DHCP.py
index 653b1e5..8a36efd 100644
--- a/src/test/utils/DHCP.py
+++ b/src/test/utils/DHCP.py
@@ -28,6 +28,9 @@
self.mac_inverse_map = {}
self.bootpmac = None
self.dhcpresp = None
+ self.servermac = None
+ self.after_T2 = False
+
def is_mcast(self, ip):
mcast_octet = (atol(ip) >> 24) & 0xff
@@ -92,17 +95,16 @@
if desired:
L6 = DHCP(options=[("message-type","discover"),("requested_addr",self.seed_ip),"end"])
- elif time:
+ elif lease_time:
L6 = DHCP(options=[("message-type","discover"),("lease_time",700),"end"])
- elif lease_time:
- L6 = DHCP(options=[("message-type","discover"),"end"])
-
+ else:
+ L6 = DHCP(options=[("message-type","discover"),"end"])
resp = srp1(L2/L3/L4/L5/L6, filter="udp and port 68", timeout=10, iface=self.iface)
if resp == None:
- return (None, None, None)
+ return (None, None, mac)
self.dhcpresp = resp
for x in resp.lastlayer().options:
@@ -120,23 +122,16 @@
print "In Attribute error."
print("Failed to acquire IP via DHCP for %s on interface %s" %(mac, self.iface))
return (None, None, None)
-
- if lease_time == True:
- for x in resp.lastlayer().options:
- if(x == 'end'):
- break
- op,val = x
- if(op == "lease_time"):
- return (srcIP, serverIP, mac, val)
- else:
- return (srcIP, serverIP, mac)
-
+
+
+ return (srcIP, serverIP, mac)
+
elif(val == 6):
return (None, None, mac)
- def only_request(self, cip, mac):
+ def only_request(self, cip, mac, cl_reboot = False, lease_time = False, renew_time = False, rebind_time = False, unicast = False):
'''Send a DHCP offer'''
subnet_mask = "0.0.0.0"
@@ -149,12 +144,29 @@
elif(op == 'server_id'):
server_id = val
- L2 = Ether(dst="ff:ff:ff:ff:ff:ff", src=mac)
- L3 = IP(src="0.0.0.0", dst="255.255.255.255")
+ if unicast and self.servermac:
+ L2 = Ether(dst=self.servermac, src=mac)
+ L3 = IP(src=cip, dst=server_id)
+ else:
+ L2 = Ether(dst="ff:ff:ff:ff:ff:ff", src=mac)
+ if self.after_T2:
+ L3 = IP(src=cip, dst="255.255.255.255")
+ else:
+ L3 = IP(src="0.0.0.0", dst="255.255.255.255")
L4 = UDP(sport=68, dport=67)
- L5 = BOOTP(chaddr=self.bootpmac, yiaddr=cip)
- L6 = DHCP(options=[("message-type","request"), ("server_id",server_id),
- ("subnet_mask",subnet_mask), ("requested_addr",cip), "end"])
+
+ if self.after_T2 == True:
+ L5 = BOOTP(chaddr=self.bootpmac, ciaddr = cip)
+ else:
+
+ L5 = BOOTP(chaddr=self.bootpmac, yiaddr=cip)
+
+ if cl_reboot or self.after_T2:
+ L6 = DHCP(options=[("message-type","request"),("subnet_mask",subnet_mask), ("requested_addr",cip), "end"])
+ else:
+ L6 = DHCP(options=[("message-type","request"), ("server_id",server_id),
+ ("subnet_mask",subnet_mask), ("requested_addr",cip), "end"])
+
resp=srp1(L2/L3/L4/L5/L6, filter="udp and port 68", timeout=10, iface=self.iface)
if resp == None:
return (None, None)
@@ -174,11 +186,32 @@
print "In Attribute error."
print("Failed to acquire IP via DHCP for %s on interface %s" %(mac, self.iface))
return (None, None)
- self.mac_map[mac] = (srcIP, serverIP)
- self.mac_inverse_map[srcIP] = (mac, serverIP)
-
- return (srcIP, serverIP)
-
+
+ if lease_time or renew_time or rebind_time:
+ for x in resp.lastlayer().options:
+ if(x == 'end'):
+ break
+ op,val = x
+
+ if op == "lease_time":
+ if lease_time == True:
+ self.mac_map[mac] = (srcIP, serverIP)
+ self.mac_inverse_map[srcIP] = (mac, serverIP)
+ return (srcIP, serverIP, val)
+ elif op == "renewal_time":
+ if renew_time == True:
+ self.mac_map[mac] = (srcIP, serverIP)
+ self.mac_inverse_map[srcIP] = (mac, serverIP)
+ return (srcIP, serverIP, val)
+ elif op == "rebinding_time":
+ if rebind_time == True:
+ self.mac_map[mac] = (srcIP, serverIP)
+ self.mac_inverse_map[srcIP] = (mac, serverIP)
+ return (srcIP, serverIP, val)
+ else:
+ self.mac_map[mac] = (srcIP, serverIP)
+ self.mac_inverse_map[srcIP] = (mac, serverIP)
+ return (srcIP, serverIP)
elif(val == 6):
return (None, None)