Merge pull request #9 from cgaonker/master
igmp app compatibility with latest onos
diff --git a/src/test/apps/ciena-cordigmp-1.0-SNAPSHOT.oar b/src/test/apps/ciena-cordigmp-1.0-SNAPSHOT.oar
index 7f1a19d..31b83b4 100644
--- a/src/test/apps/ciena-cordigmp-1.0-SNAPSHOT.oar
+++ b/src/test/apps/ciena-cordigmp-1.0-SNAPSHOT.oar
Binary files differ
diff --git a/src/test/apps/ciena-cordigmp-onos-1.5.oar b/src/test/apps/ciena-cordigmp-onos-1.5.oar
new file mode 100644
index 0000000..7f1a19d
--- /dev/null
+++ b/src/test/apps/ciena-cordigmp-onos-1.5.oar
Binary files differ
diff --git a/src/test/apps/ciena-cordigmp/pom.xml b/src/test/apps/ciena-cordigmp/pom.xml
index 1776949..058b8f8 100644
--- a/src/test/apps/ciena-cordigmp/pom.xml
+++ b/src/test/apps/ciena-cordigmp/pom.xml
@@ -27,9 +27,8 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <onos.version>1.5.0</onos.version>
+ <onos.version>1.6.0-SNAPSHOT</onos.version>
<onos.app.name>org.ciena.cordigmp</onos.app.name>
- <onos.app.requires>org.onosproject.olt</onos.app.requires>
<onos.app.title>Ciena IGMP for OVS</onos.app.title>
<onos.app.origin>Ciena Inc.</onos.app.origin>
<onos.app.category>default</onos.app.category>
@@ -51,6 +50,12 @@
</dependency>
<dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-cord-config</artifactId>
+ <version>${onos.version}</version>
+ </dependency>
+
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
diff --git a/src/test/apps/ciena-cordigmp/src/main/java/org/ciena/cordigmp/CordIgmp.java b/src/test/apps/ciena-cordigmp/src/main/java/org/ciena/cordigmp/CordIgmp.java
index 586854d..2029a4a 100644
--- a/src/test/apps/ciena-cordigmp/src/main/java/org/ciena/cordigmp/CordIgmp.java
+++ b/src/test/apps/ciena-cordigmp/src/main/java/org/ciena/cordigmp/CordIgmp.java
@@ -15,9 +15,6 @@
*/
package org.ciena.cordigmp;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.ArrayNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Multiset;
@@ -33,7 +30,6 @@
import org.onlab.packet.Ethernet;
import org.onlab.packet.IpAddress;
import org.onosproject.cfg.ComponentConfigService;
-import org.onosproject.codec.CodecService;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
import org.onosproject.net.ConnectPoint;
@@ -65,9 +61,8 @@
import org.onosproject.net.mcast.McastRoute;
import org.onosproject.net.mcast.McastRouteInfo;
import org.onosproject.net.mcast.MulticastRouteService;
-import org.onosproject.olt.AccessDeviceConfig;
-import org.onosproject.olt.AccessDeviceData;
-import org.onosproject.rest.AbstractWebResource;
+import org.onosproject.cordconfig.access.AccessDeviceConfig;
+import org.onosproject.cordconfig.access.AccessDeviceData;
import org.osgi.service.component.ComponentContext;
import org.onosproject.net.PortNumber;
import org.onlab.packet.IPv4;
@@ -97,13 +92,9 @@
public class CordIgmp {
- private static final int DEFAULT_REST_TIMEOUT_MS = 2000;
private static final int DEFAULT_PRIORITY = 500;
private static final short DEFAULT_MCAST_VLAN = 4000;
- private static final String DEFAULT_SYNC_HOST = "localhost:8181";
- private static final String DEFAULT_USER = "karaf";
- private static final String DEFAULT_PASSWORD = "karaf";
- private static final boolean DEFAULT_VLAN_ENABLED = true;
+ private static final boolean DEFAULT_VLAN_ENABLED = false;
private static final short DEFAULT_INPUT_PORT = 2;
private static final short DEFAULT_OUTPUT_PORT = 1;
private final Logger log = getLogger(getClass());
@@ -118,9 +109,6 @@
protected CoreService coreService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected CodecService codecService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected ComponentConfigService componentConfigService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
@@ -160,18 +148,6 @@
label = "Priority for multicast rules")
private int priority = DEFAULT_PRIORITY;
- @Property(name = "syncHost", value = DEFAULT_SYNC_HOST,
- label = "host:port to synchronize routes to")
- private String syncHost = DEFAULT_SYNC_HOST;
-
- @Property(name = "username", value = DEFAULT_USER,
- label = "Username for REST password authentication")
- private String user = DEFAULT_USER;
-
- @Property(name = "password", value = DEFAULT_PASSWORD,
- label = "Password for REST authentication")
- private String password = DEFAULT_PASSWORD;
-
@Property(name = "inputPort", intValue = DEFAULT_INPUT_PORT,
label = "Input port for OVS multicast traffic")
private int inputPort = DEFAULT_INPUT_PORT;
@@ -180,8 +156,6 @@
label = "Output port for OVS multicast traffic")
private int outputPort = DEFAULT_OUTPUT_PORT;
- private String fabricOnosUrl;
-
private Map<DeviceId, AccessDeviceData> oltData = new ConcurrentHashMap<>();
private Map<DeviceId, Boolean> deviceAvailability = new ConcurrentHashMap<>();
@@ -258,13 +232,7 @@
Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties();
try {
- String s = get(properties, "username");
- user = isNullOrEmpty(s) ? DEFAULT_USER : s.trim();
-
- s = get(properties, "password");
- password = isNullOrEmpty(s) ? DEFAULT_PASSWORD : s.trim();
-
- s = get(properties, "mcastVlan");
+ String s = get(properties, "mcastVlan");
mcastVlan = isNullOrEmpty(s) ? DEFAULT_MCAST_VLAN : Short.parseShort(s.trim());
s = get(properties, "vlanEnabled");
@@ -273,10 +241,6 @@
s = get(properties, "priority");
priority = isNullOrEmpty(s) ? DEFAULT_PRIORITY : Integer.parseInt(s.trim());
- s = get(properties, "syncHost");
- syncHost = isNullOrEmpty(s) ? DEFAULT_SYNC_HOST : s.trim();
- log.warn("Sync Host = " + syncHost);
-
s = get(properties, "inputPort");
inputPort = isNullOrEmpty(s) ? DEFAULT_INPUT_PORT : Short.parseShort(s.trim());
@@ -284,20 +248,12 @@
outputPort = isNullOrEmpty(s) ? DEFAULT_OUTPUT_PORT : Short.parseShort(s.trim());
} catch (Exception e) {
- user = DEFAULT_USER;
- password = DEFAULT_PASSWORD;
- syncHost = DEFAULT_SYNC_HOST;
mcastVlan = DEFAULT_MCAST_VLAN;
vlanEnabled = false;
priority = DEFAULT_PRIORITY;
inputPort = DEFAULT_INPUT_PORT;
outputPort = DEFAULT_OUTPUT_PORT;
}
- fabricOnosUrl = createRemoteUrl(syncHost);
- }
-
- private static String createRemoteUrl(String remoteHost) {
- return "http://" + remoteHost + "/onos/v1/mcast";
}
private class InternalMulticastListener implements McastListener {
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/igmp/igmpTest.py b/src/test/igmp/igmpTest.py
index 5b197f7..be28331 100644
--- a/src/test/igmp/igmpTest.py
+++ b/src/test/igmp/igmpTest.py
@@ -178,7 +178,7 @@
igmp = IGMPv3(type = IGMP_TYPE_V3_MEMBERSHIP_REPORT, max_resp_code=30,
gaddr=self.IP_DST)
for g in groups:
- gr = IGMPv3gr(rtype=IGMP_V3_GR_TYPE_EXCLUDE, mcaddr=g)
+ gr = IGMPv3gr(rtype=IGMP_V3_GR_TYPE_INCLUDE, mcaddr=g)
gr.sources = src_list
igmp.grps.append(gr)
if ip_pkt is None:
@@ -194,7 +194,7 @@
igmp = IGMPv3(type = IGMP_TYPE_V3_MEMBERSHIP_REPORT, max_resp_code=30,
gaddr=self.IP_DST)
for g in groups:
- gr = IGMPv3gr(rtype=IGMP_V3_GR_TYPE_EXCLUDE, mcaddr=g)
+ gr = IGMPv3gr(rtype=IGMP_V3_GR_TYPE_INCLUDE, mcaddr=g)
gr.sources = src_list
gr.sources = src_list
igmp.grps.append(gr)
@@ -218,7 +218,7 @@
igmp = IGMPv3(type = IGMP_TYPE_V3_MEMBERSHIP_REPORT, max_resp_code=30,
gaddr=self.IP_DST)
for g in groups:
- gr = IGMPv3gr(rtype=IGMP_V3_GR_TYPE_INCLUDE, mcaddr=g)
+ gr = IGMPv3gr(rtype=IGMP_V3_GR_TYPE_EXCLUDE, mcaddr=g)
gr.sources = src_list
igmp.grps.append(gr)
if ip_pkt is None:
@@ -233,7 +233,7 @@
igmp = IGMPv3(type = IGMP_TYPE_V3_MEMBERSHIP_REPORT, max_resp_code=30,
gaddr=self.IP_DST)
for g in groups:
- gr = IGMPv3gr(rtype=IGMP_V3_GR_TYPE_INCLUDE, mcaddr=g)
+ gr = IGMPv3gr(rtype=IGMP_V3_GR_TYPE_EXCLUDE, mcaddr=g)
gr.sources = src_list
igmp.grps.append(gr)
if ip_pkt is None:
@@ -345,7 +345,7 @@
igmp = IGMPv3(type = IGMP_TYPE_V3_MEMBERSHIP_REPORT, max_resp_code=30,
gaddr=self.IP_DST)
for g in groups:
- gr = IGMPv3gr(rtype = IGMP_V3_GR_TYPE_EXCLUDE, mcaddr = g)
+ gr = IGMPv3gr(rtype = IGMP_V3_GR_TYPE_INCLUDE, mcaddr = g)
gr.sources = src_list
igmp.grps.append(gr)
@@ -397,7 +397,7 @@
log.info('Multicast packet %s received for left groups %s' %(pkt[IP].dst, groups))
global NEGATIVE_TRAFFIC_STATUS
NEGATIVE_TRAFFIC_STATUS = 2
- sniff(prn = igmp_recv_cb, count = 1, lfilter = lambda p: p[IP].dst in groups,
+ sniff(prn = igmp_recv_cb, count = 1, lfilter = lambda p: IP in p and p[IP].dst in groups,
timeout = 3, opened_socket = recv_socket)
recv_socket.close()
return NEGATIVE_TRAFFIC_STATUS
diff --git a/src/test/setup/eval.sh b/src/test/setup/eval.sh
index adccf10..f37b0c4 100755
--- a/src/test/setup/eval.sh
+++ b/src/test/setup/eval.sh
@@ -9,10 +9,10 @@
echo "Running TLS authentication test"
$cord_tester -r -t tls
echo "Running DHCP request test"
-$cord_tester -q -t dhcp:dhcp_exchange.test_dhcp_1request
+$cord_tester -q -t dhcp
docker kill cord-onos || true
echo "Running IGMP join verify test"
$cord_tester -q -o $ONOS_IGMP -t igmp:igmp_exchange.test_igmp_join_verify_traffic
docker kill cord-onos || true
echo "Running VROUTER test with 5 routes"
-$cord_tester -q -t vrouter:vrouter_exchange.test_vrouter_1
\ No newline at end of file
+$cord_tester -q -t vrouter:vrouter_exchange.test_vrouter_1
diff --git a/src/test/utils/Channels.py b/src/test/utils/Channels.py
index 5e8cd88..ccfebb5 100644
--- a/src/test/utils/Channels.py
+++ b/src/test/utils/Channels.py
@@ -55,7 +55,7 @@
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 = IGMPv3gr(rtype=IGMP_V3_GR_TYPE_INCLUDE, mcaddr=g)
gr.sources = self.src_list
igmp.grps.append(gr)
@@ -69,7 +69,7 @@
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 = IGMPv3gr(rtype=IGMP_V3_GR_TYPE_EXCLUDE, mcaddr=g)
gr.sources = self.src_list
igmp.grps.append(gr)
@@ -132,7 +132,7 @@
IgmpChannel.__init__(self, ssm_list = self.channels, iface=iface)
def generate(self, num, channel_start = 0):
- start = (224 << 24) | ( ( (channel_start >> 16) & 0xff) << 16 ) | \
+ start = (225 << 24) | ( ( (channel_start >> 16) & 0xff) << 16 ) | \
( ( (channel_start >> 8) & 0xff ) << 8 ) | (channel_start) & 0xff
start += channel_start/256 + 1
end = start + num
@@ -248,7 +248,7 @@
groups = (self.gaddr(chan),)
if cb is None:
cb = self.recv_cb
- sniff(prn = cb, count=count, lfilter = lambda p: p[IP].dst in groups, opened_socket = self.recv_sock)
+ sniff(prn = cb, count=count, lfilter = lambda p: IP in p and p[IP].dst in groups, opened_socket = self.recv_sock)
def stop(self):
if self.streams:
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)