Search in sources :

Example 1 with DefaultHost

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

the class InstancePortManagerTest method testCreateAndUpdateInstancePort.

/**
 * Tests updating an instance port, and checks if it triggers proper events.
 */
@Test
public void testCreateAndUpdateInstancePort() {
    target.createInstancePort(instancePort1);
    assertEquals("Number of instance port did not match", 1, target.instancePorts().size());
    assertEquals("Instance port did not match", PORT_NUM_1, target.instancePort(PORT_ID_1).portNumber());
    HostLocation location = new HostLocation(DEV_ID_2, PORT_NUM_2, TIME_2);
    DefaultAnnotations.Builder annotations = DefaultAnnotations.builder().set(ANNOTATION_NETWORK_ID, NETWORK_ID_2).set(ANNOTATION_PORT_ID, PORT_ID_1).set(ANNOTATION_CREATE_TIME, String.valueOf(TIME_2));
    Host host = new DefaultHost(PROVIDER_ID, HOST_ID_2, MAC_ADDRESS_2, VLAN_ID, location, ImmutableSet.of(IP_ADDRESS_2), annotations.build());
    final InstancePort updated = DefaultInstancePort.from(host, ACTIVE);
    target.updateInstancePort(updated);
    assertEquals("Number of instance port did not match", 1, target.instancePorts().size());
    assertEquals("Instance port did not match", PORT_NUM_2, target.instancePort(PORT_ID_1).portNumber());
    validateEvents(OPENSTACK_INSTANCE_PORT_DETECTED, OPENSTACK_INSTANCE_PORT_UPDATED);
}
Also used : DefaultHost(org.onosproject.net.DefaultHost) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) HostLocation(org.onosproject.net.HostLocation) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) Host(org.onosproject.net.Host) DefaultHost(org.onosproject.net.DefaultHost) Test(org.junit.Test)

Example 2 with DefaultHost

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

the class InstancePortManagerTest method setUp.

/**
 * Initial setup for this unit test.
 */
@Before
public void setUp() {
    store = new DistributedInstancePortStore();
    TestUtils.setField(store, "coreService", new TestCoreService());
    TestUtils.setField(store, "storageService", new TestStorageService());
    TestUtils.setField(store, "eventExecutor", MoreExecutors.newDirectExecutorService());
    store.activate();
    target = new InstancePortManager();
    TestUtils.setField(target, "coreService", new TestCoreService());
    TestUtils.setField(target, "hostService", new TestHostService());
    TestUtils.setField(target, "leadershipService", new TestLeadershipService());
    TestUtils.setField(target, "clusterService", new TestClusterService());
    target.instancePortStore = store;
    target.addListener(testInstancePortListener);
    target.activate();
    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);
    instancePort2 = DefaultInstancePort.from(host2, INACTIVE);
}
Also used : DefaultHost(org.onosproject.net.DefaultHost) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) TestStorageService(org.onosproject.store.service.TestStorageService) HostLocation(org.onosproject.net.HostLocation) Host(org.onosproject.net.Host) DefaultHost(org.onosproject.net.DefaultHost) Before(org.junit.Before)

Example 3 with DefaultHost

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

the class UiTopologyTest method mockTopology.

@Test
public void mockTopology() {
    host = new DefaultHost(PID, HID, MAC_ADDRESS, VID, LOC, IPSET);
    uiHost = new UiHost(topo, host);
    deviceLink = new UiDeviceLink(topo, DX1_DY2);
    edgeLink = DefaultEdgeLink.createEdgeLink(CP, true);
    linkId = UiLinkId.uiLinkId(edgeLink);
    uiEdgeLink = new UiEdgeLink(topo, linkId);
    mem1 = clusterMember(MID, 001);
    region1 = region();
    dev1 = device();
    Set<DeviceId> deviceIds = new HashSet<>();
    Set<HostId> hostIds = new HashSet<>();
    topo.add(uiHost);
    topo.add(mem1);
    topo.add(region1);
    topo.add(dev1);
    topo.add(deviceLink);
    topo.add(uiEdgeLink);
    assertTrue(topo.allRegions().contains(region1));
    assertTrue(topo.allClusterMembers().contains(mem1));
    assertTrue(topo.findClusterMember(NodeId.nodeId("id1")).equals(mem1));
    assertTrue(topo.findRegion(R1).equals(region1));
    assertTrue(topo.findDevice(DID).equals(dev1));
    assertTrue(topo.findHost(HID).equals(uiHost));
    assertTrue(topo.findDeviceLink(DX1_DY2).equals(deviceLink));
    deviceIds.add(DID);
    assertTrue(topo.deviceSet(deviceIds).contains(dev1));
    hostIds.add(HID);
    assertTrue(topo.hostSet(hostIds).contains(uiHost));
    topo.clear();
    assertThat(topo.allClusterMembers(), is(empty()));
    assertThat(topo.allDeviceLinks(), is(empty()));
    assertThat(topo.allDevices(), is(empty()));
    assertThat(topo.allHosts(), is(empty()));
    assertThat(topo.allRegions(), is(empty()));
}
Also used : DefaultHost(org.onosproject.net.DefaultHost) DeviceId(org.onosproject.net.DeviceId) HostId(org.onosproject.net.HostId) HashSet(java.util.HashSet) Test(org.junit.Test) AbstractUiModelTest(org.onosproject.ui.model.AbstractUiModelTest)

Example 4 with DefaultHost

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

the class DistributedHostStore method createOrUpdateHost.

// TODO No longer need to return HostEvent
@Override
public HostEvent createOrUpdateHost(ProviderId providerId, HostId hostId, HostDescription hostDescription, boolean replaceIPs) {
    hostsConsistentMap.computeIf(hostId, existingHost -> shouldUpdate(existingHost, providerId, hostDescription, replaceIPs), (id, existingHost) -> {
        final Set<IpAddress> addresses;
        if (existingHost == null || replaceIPs) {
            addresses = ImmutableSet.copyOf(hostDescription.ipAddress());
        } else {
            addresses = Sets.newHashSet(existingHost.ipAddresses());
            addresses.addAll(hostDescription.ipAddress());
        }
        final Annotations annotations;
        if (existingHost != null) {
            annotations = merge((DefaultAnnotations) existingHost.annotations(), hostDescription.annotations());
        } else {
            annotations = hostDescription.annotations();
        }
        return new DefaultHost(providerId, hostId, hostDescription.hwAddress(), hostDescription.vlan(), hostDescription.locations(), hostDescription.auxLocations(), addresses, hostDescription.innerVlan(), hostDescription.tpid(), hostDescription.configured(), false, annotations);
    });
    return null;
}
Also used : DefaultHost(org.onosproject.net.DefaultHost) Annotations(org.onosproject.net.Annotations) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) IpAddress(org.onlab.packet.IpAddress)

Example 5 with DefaultHost

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

the class HostResourceTest method testHostsArray.

/**
 * Tests the result of the rest api GET when hosts are defined.
 */
@Test
public void testHostsArray() {
    replay(mockHostService);
    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);
    final MacAddress mac2 = MacAddress.valueOf("00:00:11:00:00:02");
    final Set<IpAddress> ips2 = ImmutableSet.of(IpAddress.valueOf("2222:2222:2222:1::"), IpAddress.valueOf("2222:2222:2222:2::"));
    final Host host2 = new DefaultHost(pid, HostId.hostId(mac2), valueOf(2), vlanId((short) 2), new HostLocation(DeviceId.deviceId("2"), portNumber(22), 2), ips2);
    hosts.add(host1);
    hosts.add(host2);
    WebTarget wt = target();
    String response = wt.path("hosts").request().get(String.class);
    assertThat(response, containsString("{\"hosts\":["));
    final JsonObject result = Json.parse(response).asObject();
    assertThat(result, notNullValue());
    assertThat(result.names(), hasSize(1));
    assertThat(result.names().get(0), is("hosts"));
    final JsonArray hosts = result.get("hosts").asArray();
    assertThat(hosts, notNullValue());
    assertThat(hosts, hasHost(host1));
    assertThat(hosts, hasHost(host2));
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) JsonArray(com.eclipsesource.json.JsonArray) 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)

Aggregations

DefaultHost (org.onosproject.net.DefaultHost)14 HostLocation (org.onosproject.net.HostLocation)12 IpAddress (org.onlab.packet.IpAddress)8 MacAddress (org.onlab.packet.MacAddress)7 Host (org.onosproject.net.Host)6 Test (org.junit.Test)5 ProviderId (org.onosproject.net.provider.ProviderId)5 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 VlanId (org.onlab.packet.VlanId)3 Annotations (org.onosproject.net.Annotations)3 DeviceId (org.onosproject.net.DeviceId)2 JsonArray (com.eclipsesource.json.JsonArray)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1