Committed by
Gerrit Code Review
Removing DHCPMessageType as DHCPPacketType Class was already defined
Change-Id: I01e6f8cb5a1eedba11f1f24cc19a27ef2d815b38
Showing
3 changed files
with
17 additions
and
31 deletions
... | @@ -25,6 +25,7 @@ import org.apache.felix.scr.annotations.Service; | ... | @@ -25,6 +25,7 @@ import org.apache.felix.scr.annotations.Service; |
25 | import org.onlab.packet.ARP; | 25 | import org.onlab.packet.ARP; |
26 | import org.onlab.packet.DHCP; | 26 | import org.onlab.packet.DHCP; |
27 | import org.onlab.packet.DHCPOption; | 27 | import org.onlab.packet.DHCPOption; |
28 | +import org.onlab.packet.DHCPPacketType; | ||
28 | import org.onlab.packet.Ethernet; | 29 | import org.onlab.packet.Ethernet; |
29 | import org.onlab.packet.IPv4; | 30 | import org.onlab.packet.IPv4; |
30 | import org.onlab.packet.Ip4Address; | 31 | import org.onlab.packet.Ip4Address; |
... | @@ -435,20 +436,20 @@ public class DHCPManager implements DHCPService { | ... | @@ -435,20 +436,20 @@ public class DHCPManager implements DHCPService { |
435 | } | 436 | } |
436 | 437 | ||
437 | String ipOffered = ""; | 438 | String ipOffered = ""; |
438 | - DHCP.DHCPMessageType outgoingPacketType; | 439 | + DHCPPacketType outgoingPacketType; |
439 | MacAddress clientMAC = new MacAddress(dhcpPayload.getClientHardwareAddress()); | 440 | MacAddress clientMAC = new MacAddress(dhcpPayload.getClientHardwareAddress()); |
440 | 441 | ||
441 | - if (incomingPacketType == DHCP.DHCPMessageType.MessageType_Discover.getValue()) { | 442 | + if (incomingPacketType == DHCPPacketType.DHCPDISCOVER.getValue()) { |
442 | 443 | ||
443 | - outgoingPacketType = DHCP.DHCPMessageType.MessageType_Offer; | 444 | + outgoingPacketType = DHCPPacketType.DHCPOFFER; |
444 | ipOffered = dhcpStore.suggestIP(clientMAC, requestedIP).toString(); | 445 | ipOffered = dhcpStore.suggestIP(clientMAC, requestedIP).toString(); |
445 | 446 | ||
446 | - Ethernet ethReply = buildReply(packet, ipOffered, outgoingPacketType.getValue()); | 447 | + Ethernet ethReply = buildReply(packet, ipOffered, (byte) outgoingPacketType.getValue()); |
447 | sendReply(context, ethReply); | 448 | sendReply(context, ethReply); |
448 | 449 | ||
449 | - } else if (incomingPacketType == DHCP.DHCPMessageType.MessageType_Request.getValue()) { | 450 | + } else if (incomingPacketType == DHCPPacketType.DHCPREQUEST.getValue()) { |
450 | 451 | ||
451 | - outgoingPacketType = DHCP.DHCPMessageType.MessageType_ACK; | 452 | + outgoingPacketType = DHCPPacketType.DHCPACK; |
452 | 453 | ||
453 | if (flagIfServerIP && flagIfRequestedIP) { | 454 | if (flagIfServerIP && flagIfRequestedIP) { |
454 | // SELECTING state | 455 | // SELECTING state |
... | @@ -456,7 +457,7 @@ public class DHCPManager implements DHCPService { | ... | @@ -456,7 +457,7 @@ public class DHCPManager implements DHCPService { |
456 | dhcpStore.assignIP(clientMAC, requestedIP, leaseTime)) { | 457 | dhcpStore.assignIP(clientMAC, requestedIP, leaseTime)) { |
457 | 458 | ||
458 | Ethernet ethReply = buildReply(packet, requestedIP.toString(), | 459 | Ethernet ethReply = buildReply(packet, requestedIP.toString(), |
459 | - outgoingPacketType.getValue()); | 460 | + (byte) outgoingPacketType.getValue()); |
460 | sendReply(context, ethReply); | 461 | sendReply(context, ethReply); |
461 | discoverHost(context, requestedIP); | 462 | discoverHost(context, requestedIP); |
462 | } | 463 | } |
... | @@ -464,7 +465,7 @@ public class DHCPManager implements DHCPService { | ... | @@ -464,7 +465,7 @@ public class DHCPManager implements DHCPService { |
464 | // INIT-REBOOT state | 465 | // INIT-REBOOT state |
465 | if (dhcpStore.assignIP(clientMAC, requestedIP, leaseTime)) { | 466 | if (dhcpStore.assignIP(clientMAC, requestedIP, leaseTime)) { |
466 | Ethernet ethReply = buildReply(packet, requestedIP.toString(), | 467 | Ethernet ethReply = buildReply(packet, requestedIP.toString(), |
467 | - outgoingPacketType.getValue()); | 468 | + (byte) outgoingPacketType.getValue()); |
468 | sendReply(context, ethReply); | 469 | sendReply(context, ethReply); |
469 | discoverHost(context, requestedIP); | 470 | discoverHost(context, requestedIP); |
470 | } | 471 | } |
... | @@ -475,13 +476,13 @@ public class DHCPManager implements DHCPService { | ... | @@ -475,13 +476,13 @@ public class DHCPManager implements DHCPService { |
475 | Ip4Address clientIaddr = Ip4Address.valueOf(ciaadr); | 476 | Ip4Address clientIaddr = Ip4Address.valueOf(ciaadr); |
476 | if (dhcpStore.assignIP(clientMAC, clientIaddr, leaseTime)) { | 477 | if (dhcpStore.assignIP(clientMAC, clientIaddr, leaseTime)) { |
477 | Ethernet ethReply = buildReply(packet, clientIaddr.toString(), | 478 | Ethernet ethReply = buildReply(packet, clientIaddr.toString(), |
478 | - outgoingPacketType.getValue()); | 479 | + (byte) outgoingPacketType.getValue()); |
479 | sendReply(context, ethReply); | 480 | sendReply(context, ethReply); |
480 | discoverHost(context, clientIaddr); | 481 | discoverHost(context, clientIaddr); |
481 | } | 482 | } |
482 | } | 483 | } |
483 | } | 484 | } |
484 | - } else if (incomingPacketType == DHCP.DHCPMessageType.MessageType_Release.getValue()) { | 485 | + } else if (incomingPacketType == DHCPPacketType.DHCPRELEASE.getValue()) { |
485 | 486 | ||
486 | dhcpStore.releaseIP(clientMAC); | 487 | dhcpStore.releaseIP(clientMAC); |
487 | } | 488 | } | ... | ... |
... | @@ -21,6 +21,7 @@ import org.junit.Before; | ... | @@ -21,6 +21,7 @@ import org.junit.Before; |
21 | import org.junit.Test; | 21 | import org.junit.Test; |
22 | import org.onlab.packet.DHCP; | 22 | import org.onlab.packet.DHCP; |
23 | import org.onlab.packet.DHCPOption; | 23 | import org.onlab.packet.DHCPOption; |
24 | +import org.onlab.packet.DHCPPacketType; | ||
24 | import org.onlab.packet.Ethernet; | 25 | import org.onlab.packet.Ethernet; |
25 | import org.onlab.packet.IPv4; | 26 | import org.onlab.packet.IPv4; |
26 | import org.onlab.packet.Ip4Address; | 27 | import org.onlab.packet.Ip4Address; |
... | @@ -102,7 +103,7 @@ public class DHCPManagerTest { | ... | @@ -102,7 +103,7 @@ public class DHCPManagerTest { |
102 | */ | 103 | */ |
103 | @Test | 104 | @Test |
104 | public void testDiscover() { | 105 | public void testDiscover() { |
105 | - Ethernet reply = constructDHCPPacket(DHCP.DHCPMessageType.MessageType_Discover); | 106 | + Ethernet reply = constructDHCPPacket(DHCPPacketType.DHCPDISCOVER); |
106 | sendPacket(reply); | 107 | sendPacket(reply); |
107 | } | 108 | } |
108 | 109 | ||
... | @@ -111,7 +112,7 @@ public class DHCPManagerTest { | ... | @@ -111,7 +112,7 @@ public class DHCPManagerTest { |
111 | */ | 112 | */ |
112 | @Test | 113 | @Test |
113 | public void testRequest() { | 114 | public void testRequest() { |
114 | - Ethernet reply = constructDHCPPacket(DHCP.DHCPMessageType.MessageType_Request); | 115 | + Ethernet reply = constructDHCPPacket(DHCPPacketType.DHCPREQUEST); |
115 | sendPacket(reply); | 116 | sendPacket(reply); |
116 | } | 117 | } |
117 | 118 | ||
... | @@ -131,10 +132,10 @@ public class DHCPManagerTest { | ... | @@ -131,10 +132,10 @@ public class DHCPManagerTest { |
131 | 132 | ||
132 | /** | 133 | /** |
133 | * Constructs an Ethernet packet containing a DHCP Payload. | 134 | * Constructs an Ethernet packet containing a DHCP Payload. |
134 | - * @param messageType DHCP Message Type | 135 | + * @param packetType DHCP Message Type |
135 | * @return Ethernet packet | 136 | * @return Ethernet packet |
136 | */ | 137 | */ |
137 | - private Ethernet constructDHCPPacket(DHCP.DHCPMessageType messageType) { | 138 | + private Ethernet constructDHCPPacket(DHCPPacketType packetType) { |
138 | 139 | ||
139 | // Ethernet Frame. | 140 | // Ethernet Frame. |
140 | Ethernet ethReply = new Ethernet(); | 141 | Ethernet ethReply = new Ethernet(); |
... | @@ -173,7 +174,7 @@ public class DHCPManagerTest { | ... | @@ -173,7 +174,7 @@ public class DHCPManagerTest { |
173 | // DHCP Message Type. | 174 | // DHCP Message Type. |
174 | option.setCode(DHCP.DHCPOptionCode.OptionCode_MessageType.getValue()); | 175 | option.setCode(DHCP.DHCPOptionCode.OptionCode_MessageType.getValue()); |
175 | option.setLength((byte) 1); | 176 | option.setLength((byte) 1); |
176 | - byte[] optionData = {messageType.getValue()}; | 177 | + byte[] optionData = {(byte) packetType.getValue()}; |
177 | option.setData(optionData); | 178 | option.setData(optionData); |
178 | optionList.add(option); | 179 | optionList.add(option); |
179 | 180 | ... | ... |
... | @@ -73,22 +73,6 @@ public class DHCP extends BasePacket { | ... | @@ -73,22 +73,6 @@ public class DHCP extends BasePacket { |
73 | } | 73 | } |
74 | } | 74 | } |
75 | 75 | ||
76 | - public enum DHCPMessageType { | ||
77 | - MessageType_Discover((byte) 1), MessageType_Offer((byte) 2), MessageType_Request((byte) 3), | ||
78 | - MessageType_Decline((byte) 4), MessageType_ACK((byte) 5), MessageType_Nak((byte) 6), | ||
79 | - MessageType_Release((byte) 7), MessageType_Inform((byte) 8); | ||
80 | - | ||
81 | - protected byte value; | ||
82 | - | ||
83 | - private DHCPMessageType(final byte value) { | ||
84 | - this.value = value; | ||
85 | - } | ||
86 | - | ||
87 | - public byte getValue() { | ||
88 | - return this.value; | ||
89 | - } | ||
90 | - } | ||
91 | - | ||
92 | protected byte opCode; | 76 | protected byte opCode; |
93 | protected byte hardwareType; | 77 | protected byte hardwareType; |
94 | protected byte hardwareAddressLength; | 78 | protected byte hardwareAddressLength; | ... | ... |
-
Please register or login to post a comment