Search in sources :

Example 76 with HostId

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)));
}
Also used : HostLocation(org.onosproject.net.HostLocation) PacketContext(org.onosproject.net.packet.PacketContext) HostId(org.onosproject.net.HostId) HostDescription(org.onosproject.net.host.HostDescription) Test(org.junit.Test)

Example 77 with HostId

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()));
}
Also used : HostId(org.onosproject.net.HostId) HostDescription(org.onosproject.net.host.HostDescription) Test(org.junit.Test)

Example 78 with HostId

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;
}
Also used : Versioned(org.onosproject.store.service.Versioned) HashMap(java.util.HashMap) IpAssignment(org.onosproject.dhcp.IpAssignment) HostId(org.onosproject.net.HostId) ConsistentMap(org.onosproject.store.service.ConsistentMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 79 with HostId

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();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) IpAssignment(org.onosproject.dhcp.IpAssignment) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) HostId(org.onosproject.net.HostId) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 80 with HostId

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();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) IpAssignment(org.onosproject.dhcp.IpAssignment) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) HostId(org.onosproject.net.HostId) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Aggregations

HostId (org.onosproject.net.HostId)86 IpAddress (org.onlab.packet.IpAddress)27 DeviceId (org.onosproject.net.DeviceId)24 VlanId (org.onlab.packet.VlanId)23 HostLocation (org.onosproject.net.HostLocation)23 MacAddress (org.onlab.packet.MacAddress)21 Test (org.junit.Test)18 ConnectPoint (org.onosproject.net.ConnectPoint)17 Host (org.onosproject.net.Host)17 HostDescription (org.onosproject.net.host.HostDescription)16 DefaultHostDescription (org.onosproject.net.host.DefaultHostDescription)14 Set (java.util.Set)13 DhcpRecord (org.onosproject.dhcprelay.store.DhcpRecord)12 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)11 HashSet (java.util.HashSet)11 Logger (org.slf4j.Logger)11 ImmutableSet (com.google.common.collect.ImmutableSet)10 Device (org.onosproject.net.Device)10 Path (org.onosproject.net.Path)10 LoggerFactory (org.slf4j.LoggerFactory)10