Search in sources :

Example 11 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 12 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 13 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 14 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 15 with DefaultHost

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

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