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);
}
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);
}
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()));
}
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;
}
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));
}
Aggregations