Search in sources :

Example 16 with HostLocation

use of org.onosproject.net.HostLocation 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 17 with HostLocation

use of org.onosproject.net.HostLocation 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 18 with HostLocation

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

the class ModelCache method updateHost.

private void updateHost(UiHost uiHost, Host h) {
    UiEdgeLink existing = uiTopology.findEdgeLink(uiHost.edgeLinkId());
    // TODO: review - do we need EdgeLink now that we are creating from id only?
    EdgeLink currentElink = synthesizeLink(h);
    UiLinkId currentElinkId = uiLinkId(currentElink);
    if (existing != null) {
        if (!currentElinkId.equals(existing.id())) {
            // edge link has changed
            insertNewUiEdgeLink(currentElinkId);
            uiHost.setEdgeLinkId(currentElinkId);
            uiTopology.remove(existing);
        }
    } else {
        // no previously existing edge link
        insertNewUiEdgeLink(currentElinkId);
        uiHost.setEdgeLinkId(currentElinkId);
    }
    HostLocation hloc = h.location();
    uiHost.setLocation(hloc.deviceId(), hloc.port());
}
Also used : UiEdgeLink(org.onosproject.ui.model.topo.UiEdgeLink) DefaultEdgeLink.createEdgeLink(org.onosproject.net.DefaultEdgeLink.createEdgeLink) EdgeLink(org.onosproject.net.EdgeLink) UiEdgeLink(org.onosproject.ui.model.topo.UiEdgeLink) UiLinkId(org.onosproject.ui.model.topo.UiLinkId) HostLocation(org.onosproject.net.HostLocation)

Example 19 with HostLocation

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

the class AbstractTopoModelTest method createHost.

/**
 * Creates a default host connected at the given edge device and port. Note
 * that an identifying hex character ("a" - "f") should be supplied. This
 * will be included in the MAC address of the host (and equivalent value
 * as last byte in IP address).
 *
 * @param device  edge device
 * @param port    port number
 * @param hexChar identifying hex character
 * @return host connected at that location
 */
protected static Host createHost(Device device, int port, String hexChar) {
    DeviceId deviceId = device.id();
    String devNum = deviceId.toString().substring(1);
    MacAddress mac = MacAddress.valueOf(HOST_MAC_PREFIX + devNum + hexChar);
    HostId hostId = hostId(String.format("%s/-1", mac));
    int ipByte = Integer.valueOf(hexChar, 16);
    if (ipByte < 10 || ipByte > 15) {
        throw new IllegalArgumentException("hexChar must be a-f");
    }
    HostLocation loc = new HostLocation(deviceId, portNumber(port), 0);
    IpAddress ip = ip("10." + devNum + ".0." + ipByte);
    return new DefaultHost(ProviderId.NONE, hostId, mac, VlanId.NONE, loc, ImmutableSet.of(ip));
}
Also used : DefaultHost(org.onosproject.net.DefaultHost) DeviceId(org.onosproject.net.DeviceId) HostLocation(org.onosproject.net.HostLocation) IpAddress(org.onlab.packet.IpAddress) MacAddress(org.onlab.packet.MacAddress) HostId(org.onosproject.net.HostId) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 20 with HostLocation

use of org.onosproject.net.HostLocation 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

HostLocation (org.onosproject.net.HostLocation)52 IpAddress (org.onlab.packet.IpAddress)29 MacAddress (org.onlab.packet.MacAddress)25 VlanId (org.onlab.packet.VlanId)22 HostId (org.onosproject.net.HostId)22 Host (org.onosproject.net.Host)19 ConnectPoint (org.onosproject.net.ConnectPoint)15 Test (org.junit.Test)14 DefaultHost (org.onosproject.net.DefaultHost)14 DeviceId (org.onosproject.net.DeviceId)12 HostDescription (org.onosproject.net.host.HostDescription)11 ProviderId (org.onosproject.net.provider.ProviderId)11 Set (java.util.Set)10 DefaultHostDescription (org.onosproject.net.host.DefaultHostDescription)10 Logger (org.slf4j.Logger)8 ImmutableSet (com.google.common.collect.ImmutableSet)7 Collectors (java.util.stream.Collectors)7 PortNumber (org.onosproject.net.PortNumber)7 DeviceEvent (org.onosproject.net.device.DeviceEvent)7 HostService (org.onosproject.net.host.HostService)7