Committed by
Gerrit Code Review
Fixed a few defects with DHCP server top be able to run on the office network.
Change-Id: I7a800b8ab422a4a08920ac3eeb8f25bbe5764a3a
Showing
3 changed files
with
15 additions
and
8 deletions
| ... | @@ -86,7 +86,7 @@ public class DhcpManager implements DhcpService { | ... | @@ -86,7 +86,7 @@ public class DhcpManager implements DhcpService { |
| 86 | private static final ProviderId PID = new ProviderId("of", "org.onosproject.dhcp", true); | 86 | private static final ProviderId PID = new ProviderId("of", "org.onosproject.dhcp", true); |
| 87 | private final Logger log = LoggerFactory.getLogger(getClass()); | 87 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 88 | 88 | ||
| 89 | - private final NetworkConfigListener cfgListener = new InternalConfigListener(); | 89 | + private final InternalConfigListener cfgListener = new InternalConfigListener(); |
| 90 | 90 | ||
| 91 | private final Set<ConfigFactory> factories = ImmutableSet.of( | 91 | private final Set<ConfigFactory> factories = ImmutableSet.of( |
| 92 | new ConfigFactory<ApplicationId, DhcpConfig>(APP_SUBJECT_FACTORY, | 92 | new ConfigFactory<ApplicationId, DhcpConfig>(APP_SUBJECT_FACTORY, |
| ... | @@ -163,8 +163,11 @@ public class DhcpManager implements DhcpService { | ... | @@ -163,8 +163,11 @@ public class DhcpManager implements DhcpService { |
| 163 | 163 | ||
| 164 | cfgService.addListener(cfgListener); | 164 | cfgService.addListener(cfgListener); |
| 165 | factories.forEach(cfgService::registerConfigFactory); | 165 | factories.forEach(cfgService::registerConfigFactory); |
| 166 | + cfgListener.reconfigureNetwork(cfgService.getConfig(appId, DhcpConfig.class)); | ||
| 167 | + cfgListener.reconfigureStore(cfgService.getConfig(appId, DhcpStoreConfig.class)); | ||
| 168 | + | ||
| 166 | hostProviderService = hostProviderRegistry.register(hostProvider); | 169 | hostProviderService = hostProviderRegistry.register(hostProvider); |
| 167 | - packetService.addProcessor(processor, PacketProcessor.observer(1)); | 170 | + packetService.addProcessor(processor, PacketProcessor.director(1)); |
| 168 | requestPackets(); | 171 | requestPackets(); |
| 169 | log.info("Started"); | 172 | log.info("Started"); |
| 170 | } | 173 | } |
| ... | @@ -394,7 +397,7 @@ public class DhcpManager implements DhcpService { | ... | @@ -394,7 +397,7 @@ public class DhcpManager implements DhcpService { |
| 394 | TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder(); | 397 | TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder(); |
| 395 | ConnectPoint sourcePoint = context.inPacket().receivedFrom(); | 398 | ConnectPoint sourcePoint = context.inPacket().receivedFrom(); |
| 396 | builder.setOutput(sourcePoint.port()); | 399 | builder.setOutput(sourcePoint.port()); |
| 397 | - | 400 | + context.block(); |
| 398 | packetService.emit(new DefaultOutboundPacket(sourcePoint.deviceId(), | 401 | packetService.emit(new DefaultOutboundPacket(sourcePoint.deviceId(), |
| 399 | builder.build(), ByteBuffer.wrap(reply.serialize()))); | 402 | builder.build(), ByteBuffer.wrap(reply.serialize()))); |
| 400 | } | 403 | } |
| ... | @@ -407,7 +410,6 @@ public class DhcpManager implements DhcpService { | ... | @@ -407,7 +410,6 @@ public class DhcpManager implements DhcpService { |
| 407 | * @param dhcpPayload the extracted DHCP payload | 410 | * @param dhcpPayload the extracted DHCP payload |
| 408 | */ | 411 | */ |
| 409 | private void processDHCPPacket(PacketContext context, DHCP dhcpPayload) { | 412 | private void processDHCPPacket(PacketContext context, DHCP dhcpPayload) { |
| 410 | - | ||
| 411 | Ethernet packet = context.inPacket().parsed(); | 413 | Ethernet packet = context.inPacket().parsed(); |
| 412 | boolean flagIfRequestedIP = false; | 414 | boolean flagIfRequestedIP = false; |
| 413 | boolean flagIfServerIP = false; | 415 | boolean flagIfServerIP = false; |
| ... | @@ -483,7 +485,6 @@ public class DhcpManager implements DhcpService { | ... | @@ -483,7 +485,6 @@ public class DhcpManager implements DhcpService { |
| 483 | } | 485 | } |
| 484 | } | 486 | } |
| 485 | } else if (incomingPacketType == DHCPPacketType.DHCPRELEASE.getValue()) { | 487 | } else if (incomingPacketType == DHCPPacketType.DHCPRELEASE.getValue()) { |
| 486 | - | ||
| 487 | dhcpStore.releaseIP(clientMAC); | 488 | dhcpStore.releaseIP(clientMAC); |
| 488 | } | 489 | } |
| 489 | } | 490 | } |
| ... | @@ -540,7 +541,6 @@ public class DhcpManager implements DhcpService { | ... | @@ -540,7 +541,6 @@ public class DhcpManager implements DhcpService { |
| 540 | 541 | ||
| 541 | @Override | 542 | @Override |
| 542 | public void process(PacketContext context) { | 543 | public void process(PacketContext context) { |
| 543 | - | ||
| 544 | Ethernet packet = context.inPacket().parsed(); | 544 | Ethernet packet = context.inPacket().parsed(); |
| 545 | if (packet == null) { | 545 | if (packet == null) { |
| 546 | return; | 546 | return; |
| ... | @@ -581,7 +581,9 @@ public class DhcpManager implements DhcpService { | ... | @@ -581,7 +581,9 @@ public class DhcpManager implements DhcpService { |
| 581 | * @param cfg configuration object | 581 | * @param cfg configuration object |
| 582 | */ | 582 | */ |
| 583 | private void reconfigureNetwork(DhcpConfig cfg) { | 583 | private void reconfigureNetwork(DhcpConfig cfg) { |
| 584 | - | 584 | + if (cfg == null) { |
| 585 | + return; | ||
| 586 | + } | ||
| 585 | if (cfg.ip() != null) { | 587 | if (cfg.ip() != null) { |
| 586 | myIP = cfg.ip(); | 588 | myIP = cfg.ip(); |
| 587 | } | 589 | } |
| ... | @@ -620,6 +622,9 @@ public class DhcpManager implements DhcpService { | ... | @@ -620,6 +622,9 @@ public class DhcpManager implements DhcpService { |
| 620 | * @param cfg configuration object | 622 | * @param cfg configuration object |
| 621 | */ | 623 | */ |
| 622 | private void reconfigureStore(DhcpStoreConfig cfg) { | 624 | private void reconfigureStore(DhcpStoreConfig cfg) { |
| 625 | + if (cfg == null) { | ||
| 626 | + return; | ||
| 627 | + } | ||
| 623 | 628 | ||
| 624 | if (cfg.defaultTimeout() != null) { | 629 | if (cfg.defaultTimeout() != null) { |
| 625 | dhcpStore.setDefaultTimeoutForPurge(Integer.valueOf(cfg.defaultTimeout())); | 630 | dhcpStore.setDefaultTimeoutForPurge(Integer.valueOf(cfg.defaultTimeout())); | ... | ... |
| ... | @@ -24,6 +24,8 @@ import org.onosproject.net.config.basics.BasicElementConfig; | ... | @@ -24,6 +24,8 @@ import org.onosproject.net.config.basics.BasicElementConfig; |
| 24 | */ | 24 | */ |
| 25 | public class DhcpStoreConfig extends Config<ApplicationId> { | 25 | public class DhcpStoreConfig extends Config<ApplicationId> { |
| 26 | 26 | ||
| 27 | + // FIXME: combine with the other config and properly type the values | ||
| 28 | + | ||
| 27 | public static final String TIMER_DELAY = "delay"; | 29 | public static final String TIMER_DELAY = "delay"; |
| 28 | public static final String DEFAULT_TIMEOUT = "timeout"; | 30 | public static final String DEFAULT_TIMEOUT = "timeout"; |
| 29 | public static final String START_IP = "startip"; | 31 | public static final String START_IP = "startip"; | ... | ... |
| ... | @@ -175,7 +175,7 @@ public class DistributedDhcpStore implements DhcpStore { | ... | @@ -175,7 +175,7 @@ public class DistributedDhcpStore implements DhcpStore { |
| 175 | if (allocationMap.containsKey(macID)) { | 175 | if (allocationMap.containsKey(macID)) { |
| 176 | assignmentInfo = allocationMap.get(macID).value(); | 176 | assignmentInfo = allocationMap.get(macID).value(); |
| 177 | if ((assignmentInfo.ipAddress().toInt() == ipAddr.toInt()) && | 177 | if ((assignmentInfo.ipAddress().toInt() == ipAddr.toInt()) && |
| 178 | - (ipAddr.toInt() > startIPRange.toInt()) && (ipAddr.toInt() < endIPRange.toInt())) { | 178 | + (ipAddr.toInt() >= startIPRange.toInt()) && (ipAddr.toInt() <= endIPRange.toInt())) { |
| 179 | 179 | ||
| 180 | assignmentInfo = IpAssignment.builder() | 180 | assignmentInfo = IpAssignment.builder() |
| 181 | .ipAddress(ipAddr) | 181 | .ipAddress(ipAddr) | ... | ... |
-
Please register or login to post a comment