use of org.onosproject.net.HostId in project onos by opennetworkinglab.
the class DhcpRelayManagerTest method testDhcp6DualHome.
@Test
public void testDhcp6DualHome() {
PacketContext packetContext = new TestDhcp6ReplyPacketContext(DHCP6.MsgType.REPLY.value(), CLIENT_DH_CP, CLIENT_MAC, CLIENT_VLAN, INTERFACE_IP_V6.ipAddress().getIp6Address(), 0, false, CLIENT_VLAN);
reset(manager.hostService);
expect(manager.hostService.getHostsByIp(CLIENT_LL_IP_V6)).andReturn(ImmutableSet.of(EXISTS_HOST)).anyTimes();
// FIXME: currently DHCPv6 has a bug, we can't get correct vlan of client......
// XXX: The vlan relied from DHCP6 handler might be wrong, do hack here
HostId hostId = HostId.hostId(CLIENT_MAC, VlanId.NONE);
expect(manager.hostService.getHost(hostId)).andReturn(EXISTS_HOST).anyTimes();
// XXX: sometimes this will work, sometimes not
expect(manager.hostService.getHost(CLIENT_HOST_ID)).andReturn(EXISTS_HOST).anyTimes();
Capture<HostDescription> capturedHostDesc = newCapture();
// XXX: also a hack here
mockHostProviderService.hostDetected(eq(hostId), capture(capturedHostDesc), eq(false));
expectLastCall().anyTimes();
mockHostProviderService.hostDetected(eq(CLIENT_HOST_ID), capture(capturedHostDesc), eq(false));
expectLastCall().anyTimes();
replay(mockHostProviderService, manager.hostService);
packetService.processPacket(packetContext);
assertAfter(PKT_PROCESSING_MS, () -> verify(mockHostProviderService));
assertAfter(PKT_PROCESSING_MS, () -> assertTrue(capturedHostDesc.hasCaptured()));
HostDescription hostDesc = capturedHostDesc.getValue();
Set<HostLocation> hostLocations = hostDesc.locations();
assertAfter(PKT_PROCESSING_MS, () -> assertEquals(2, hostLocations.size()));
assertAfter(PKT_PROCESSING_MS, () -> assertTrue(hostLocations.contains(CLIENT_LOCATION)));
assertAfter(PKT_PROCESSING_MS, () -> assertTrue(hostLocations.contains(CLIENT_DH_LOCATION)));
}
use of org.onosproject.net.HostId in project onos by opennetworkinglab.
the class DhcpRelayManagerTest method relayDhcpWithoutAgentInfo.
/**
* Relay a DHCP packet without option 82.
* Should add new host to host store after dhcp ack.
*/
@Test
public void relayDhcpWithoutAgentInfo() {
replay(mockHostProviderService);
// send request
packetService.processPacket(new TestDhcpRequestPacketContext(CLIENT_MAC, CLIENT_VLAN, CLIENT_CP, INTERFACE_IP.ipAddress().getIp4Address(), false));
// won't trigger the host provider service
verify(mockHostProviderService);
reset(mockHostProviderService);
assertAfter(PKT_PROCESSING_MS, () -> assertEquals(0, mockRouteStore.routes.size()));
HostId expectHostId = HostId.hostId(CLIENT_MAC, CLIENT_VLAN);
Capture<HostDescription> capturedHostDesc = newCapture();
mockHostProviderService.hostDetected(eq(expectHostId), capture(capturedHostDesc), eq(false));
replay(mockHostProviderService);
// send ack
packetService.processPacket(new TestDhcpAckPacketContext(CLIENT_CP, CLIENT_MAC, CLIENT_VLAN, INTERFACE_IP.ipAddress().getIp4Address(), false));
assertAfter(PKT_PROCESSING_MS, () -> verify(mockHostProviderService));
assertAfter(PKT_PROCESSING_MS, () -> assertEquals(0, mockRouteStore.routes.size()));
HostDescription host = capturedHostDesc.getValue();
assertAfter(PKT_PROCESSING_MS, () -> assertFalse(host.configured()));
assertAfter(PKT_PROCESSING_MS, () -> assertEquals(CLIENT_CP.deviceId(), host.location().elementId()));
assertAfter(PKT_PROCESSING_MS, () -> assertEquals(CLIENT_CP.port(), host.location().port()));
assertAfter(PKT_PROCESSING_MS, () -> assertEquals(1, host.ipAddress().size()));
assertAfter(PKT_PROCESSING_MS, () -> assertEquals(IP_FOR_CLIENT, host.ipAddress().iterator().next()));
}
use of org.onosproject.net.HostId in project onos by opennetworkinglab.
the class DistributedDhcpStore method listAssignedMapping.
@Override
public Map<HostId, IpAssignment> listAssignedMapping() {
Map<HostId, IpAssignment> validMapping = new HashMap<>();
IpAssignment assignment;
for (Map.Entry<HostId, Versioned<IpAssignment>> entry : allocationMap.entrySet()) {
assignment = entry.getValue().value();
if (assignment.assignmentStatus() == Option_Assigned || assignment.assignmentStatus() == Option_RangeNotEnforced) {
validMapping.put(entry.getKey(), assignment);
}
}
return validMapping;
}
use of org.onosproject.net.HostId in project onos by opennetworkinglab.
the class DhcpWebResource method listMappings.
/**
* Get all MAC/IP mappings.
* Shows all MAC/IP mappings held by the DHCP server.
*
* @onos.rsModel DhcpConfigGetMappings
* @return 200 OK
*/
@GET
@Path("mappings")
public Response listMappings() {
ObjectNode root = mapper().createObjectNode();
Map<HostId, IpAssignment> intents = service.listMapping();
ArrayNode arrayNode = root.putArray("mappings");
intents.entrySet().forEach(i -> arrayNode.add(mapper().createObjectNode().put("host", i.getKey().toString()).put("ip", i.getValue().ipAddress().toString())));
return ok(root).build();
}
use of org.onosproject.net.HostId in project onos by opennetworkinglab.
the class DhcpWebResource method deleteMapping.
/**
* Delete a static MAC/IP binding.
* Removes a static binding from the DHCP Server, and displays the current set of bindings.
*
* @param macID mac address identifier
* @return 200 OK
*/
@DELETE
@Path("mappings/{macID}")
public Response deleteMapping(@PathParam("macID") String macID) {
ObjectNode root = mapper().createObjectNode();
if (!service.removeStaticMapping(MacAddress.valueOf(macID))) {
throw new IllegalArgumentException("Static Mapping Removal Failed.");
}
final Map<HostId, IpAssignment> intents = service.listMapping();
ArrayNode arrayNode = root.putArray("mappings");
intents.entrySet().forEach(i -> arrayNode.add(mapper().createObjectNode().put("host", i.getKey().toString()).put("ip", i.getValue().ipAddress().toString())));
return ok(root).build();
}
Aggregations