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