Search in sources :

Example 21 with DefaultHost

use of org.onosproject.net.DefaultHost in project onos by opennetworkinglab.

the class HostServiceAdapter method getHost.

@Override
public Host getHost(HostId hostId) {
    ProviderId providerId = ProviderId.NONE;
    MacAddress mac = MacAddress.valueOf("fa:12:3e:56:ee:a2");
    VlanId vlan = VlanId.NONE;
    HostLocation location = HostLocation.NONE;
    Set<IpAddress> ips = Sets.newHashSet();
    Annotations annotations = null;
    return new DefaultHost(providerId, hostId, mac, vlan, location, ips, annotations);
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) DefaultHost(org.onosproject.net.DefaultHost) Annotations(org.onosproject.net.Annotations) HostLocation(org.onosproject.net.HostLocation) IpAddress(org.onlab.packet.IpAddress) MacAddress(org.onlab.packet.MacAddress) VlanId(org.onlab.packet.VlanId)

Example 22 with DefaultHost

use of org.onosproject.net.DefaultHost in project onos by opennetworkinglab.

the class HostCodec method decode.

@Override
public Host decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    MacAddress mac = MacAddress.valueOf(nullIsIllegal(json.get(MAC), MAC + MISSING_MEMBER_MESSAGE).asText());
    VlanId vlanId = VlanId.vlanId(nullIsIllegal(json.get(VLAN), VLAN + MISSING_MEMBER_MESSAGE).asText());
    HostId id = HostId.hostId(mac, vlanId);
    ArrayNode locationNodes = nullIsIllegal((ArrayNode) json.get(HOST_LOCATIONS), HOST_LOCATIONS + MISSING_MEMBER_MESSAGE);
    Set<HostLocation> hostLocations = context.codec(HostLocation.class).decode(locationNodes, context).stream().collect(Collectors.toSet());
    ArrayNode ipNodes = nullIsIllegal((ArrayNode) json.get(IP_ADDRESSES), IP_ADDRESSES + MISSING_MEMBER_MESSAGE);
    Set<IpAddress> ips = new HashSet<>();
    ipNodes.forEach(ipNode -> {
        ips.add(IpAddress.valueOf(ipNode.asText()));
    });
    // check optional fields
    JsonNode innerVlanIdNode = json.get(INNER_VLAN);
    VlanId innerVlanId = (null == innerVlanIdNode) ? VlanId.NONE : VlanId.vlanId(innerVlanIdNode.asText());
    JsonNode outerTpidNode = json.get(OUTER_TPID);
    EthType outerTpid = (null == outerTpidNode) ? EthType.EtherType.UNKNOWN.ethType() : EthType.EtherType.lookup((short) (Integer.decode(outerTpidNode.asText()) & 0xFFFF)).ethType();
    JsonNode configuredNode = json.get(IS_CONFIGURED);
    boolean configured = (null == configuredNode) ? false : configuredNode.asBoolean();
    JsonNode suspendedNode = json.get(IS_SUSPENDED);
    boolean suspended = (null == suspendedNode) ? false : suspendedNode.asBoolean();
    ArrayNode auxLocationNodes = (ArrayNode) json.get(AUX_LOCATIONS);
    Set<HostLocation> auxHostLocations = (null == auxLocationNodes) ? null : context.codec(HostLocation.class).decode(auxLocationNodes, context).stream().collect(Collectors.toSet());
    Annotations annotations = extractAnnotations(json, context);
    return new DefaultHost(ProviderId.NONE, id, mac, vlanId, hostLocations, auxHostLocations, ips, innerVlanId, outerTpid, configured, suspended, annotations);
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) MacAddress(org.onlab.packet.MacAddress) HostId(org.onosproject.net.HostId) DefaultHost(org.onosproject.net.DefaultHost) EthType(org.onlab.packet.EthType) Annotations(org.onosproject.net.Annotations) HostLocation(org.onosproject.net.HostLocation) IpAddress(org.onlab.packet.IpAddress) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) VlanId(org.onlab.packet.VlanId) HashSet(java.util.HashSet)

Example 23 with DefaultHost

use of org.onosproject.net.DefaultHost in project onos by opennetworkinglab.

the class HostResourceTest method testSingleHostByIdFetch.

/**
 * Tests fetch of one host by Id.
 */
@Test
public void testSingleHostByIdFetch() {
    final ProviderId pid = new ProviderId("of", "foo");
    final MacAddress mac1 = MacAddress.valueOf("00:00:11:00:00:01");
    final Set<IpAddress> ips1 = ImmutableSet.of(IpAddress.valueOf("1111:1111:1111:1::"));
    final Host host1 = new DefaultHost(pid, HostId.hostId(mac1), valueOf(1), vlanId((short) 1), new HostLocation(DeviceId.deviceId("1"), portNumber(11), 1), ips1);
    hosts.add(host1);
    expect(mockHostService.getHost(HostId.hostId("00:00:11:00:00:01/1"))).andReturn(host1).anyTimes();
    replay(mockHostService);
    WebTarget wt = target();
    String response = wt.path("hosts/00:00:11:00:00:01%2F1").request().get(String.class);
    final JsonObject result = Json.parse(response).asObject();
    assertThat(result, matchesHost(host1));
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) DefaultHost(org.onosproject.net.DefaultHost) HostLocation(org.onosproject.net.HostLocation) JsonObject(com.eclipsesource.json.JsonObject) IpAddress(org.onlab.packet.IpAddress) Host(org.onosproject.net.Host) DefaultHost(org.onosproject.net.DefaultHost) WebTarget(javax.ws.rs.client.WebTarget) Matchers.containsString(org.hamcrest.Matchers.containsString) MacAddress(org.onlab.packet.MacAddress) Test(org.junit.Test)

Example 24 with DefaultHost

use of org.onosproject.net.DefaultHost in project onos by opennetworkinglab.

the class HostResourceTest method testSingleHostByMacAndVlanFetch.

/**
 * Tests fetch of one host by mac and vlan.
 */
@Test
public void testSingleHostByMacAndVlanFetch() {
    final ProviderId pid = new ProviderId("of", "foo");
    final MacAddress mac1 = MacAddress.valueOf("00:00:11:00:00:01");
    final Set<IpAddress> ips1 = ImmutableSet.of(IpAddress.valueOf("1111:1111:1111:1::"));
    final Host host1 = new DefaultHost(pid, HostId.hostId(mac1), valueOf(1), vlanId((short) 1), new HostLocation(DeviceId.deviceId("1"), portNumber(11), 1), ips1);
    hosts.add(host1);
    expect(mockHostService.getHost(HostId.hostId("00:00:11:00:00:01/1"))).andReturn(host1).anyTimes();
    replay(mockHostService);
    WebTarget wt = target();
    String response = wt.path("hosts/00:00:11:00:00:01/1").request().get(String.class);
    final JsonObject result = Json.parse(response).asObject();
    assertThat(result, matchesHost(host1));
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) DefaultHost(org.onosproject.net.DefaultHost) HostLocation(org.onosproject.net.HostLocation) JsonObject(com.eclipsesource.json.JsonObject) IpAddress(org.onlab.packet.IpAddress) Host(org.onosproject.net.Host) DefaultHost(org.onosproject.net.DefaultHost) WebTarget(javax.ws.rs.client.WebTarget) Matchers.containsString(org.hamcrest.Matchers.containsString) MacAddress(org.onlab.packet.MacAddress) Test(org.junit.Test)

Example 25 with DefaultHost

use of org.onosproject.net.DefaultHost in project onos by opennetworkinglab.

the class DefaultInstancePortTest method setUp.

/**
 * Initial setup for this unit test.
 */
@Before
public void setUp() {
    HostLocation location1 = new HostLocation(DEV_ID_1, PORT_NUM_1, TIME_1);
    HostLocation location2 = new HostLocation(DEV_ID_2, PORT_NUM_2, TIME_2);
    DefaultAnnotations.Builder annotations1 = DefaultAnnotations.builder().set(ANNOTATION_NETWORK_ID, NETWORK_ID_1).set(ANNOTATION_PORT_ID, PORT_ID_1).set(ANNOTATION_CREATE_TIME, String.valueOf(TIME_1));
    DefaultAnnotations.Builder annotations2 = DefaultAnnotations.builder().set(ANNOTATION_NETWORK_ID, NETWORK_ID_2).set(ANNOTATION_PORT_ID, PORT_ID_2).set(ANNOTATION_CREATE_TIME, String.valueOf(TIME_2));
    Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_1, MAC_ADDRESS_1, VLAN_ID, location1, ImmutableSet.of(IP_ADDRESS_1), annotations1.build());
    Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_2, MAC_ADDRESS_2, VLAN_ID, location2, ImmutableSet.of(IP_ADDRESS_2), annotations2.build());
    instancePort1 = DefaultInstancePort.from(host1, ACTIVE);
    sameAsInstancePort1 = DefaultInstancePort.from(host1, ACTIVE);
    instancePort2 = DefaultInstancePort.from(host2, ACTIVE);
}
Also used : DefaultHost(org.onosproject.net.DefaultHost) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) HostLocation(org.onosproject.net.HostLocation) Host(org.onosproject.net.Host) DefaultHost(org.onosproject.net.DefaultHost) Before(org.junit.Before)

Aggregations

DefaultHost (org.onosproject.net.DefaultHost)36 Host (org.onosproject.net.Host)28 Test (org.junit.Test)27 HostEvent (org.onosproject.net.host.HostEvent)20 HostLocation (org.onosproject.net.HostLocation)13 IpAddress (org.onlab.packet.IpAddress)9 MacAddress (org.onlab.packet.MacAddress)8 ProviderId (org.onosproject.net.provider.ProviderId)6 VlanId (org.onlab.packet.VlanId)4 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)4 HostId (org.onosproject.net.HostId)4 JsonObject (com.eclipsesource.json.JsonObject)3 HashSet (java.util.HashSet)3 WebTarget (javax.ws.rs.client.WebTarget)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 Before (org.junit.Before)3 Annotations (org.onosproject.net.Annotations)3 DeviceId (org.onosproject.net.DeviceId)2 TestUtils.getIntReportConfig (org.stratumproject.fabric.tna.utils.TestUtils.getIntReportConfig)2 JsonArray (com.eclipsesource.json.JsonArray)1