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));
}
use of org.onosproject.net.DefaultHost in project fabric-tna by stratum.
the class FabricIntProgrammableTest method testSetUpSpineButNoCollectorHostLocation.
/**
* Test installing report rules on spine but cannot find
* the location of the collector host.
*/
@Test
public void testSetUpSpineButNoCollectorHostLocation() {
final IntReportConfig intConfig = getIntReportConfig(APP_ID, "/int-report.json");
final Host collectorHost = new DefaultHost(null, null, null, null, Sets.newHashSet(), Sets.newHashSet(), true);
final Capture<FlowRuleOperations> capturedOpsForCollector = newCapture();
final Capture<FlowRuleOperations> capturedOpsForSubnet = newCapture();
final Capture<FlowRuleOperations> capturedOpsForQueueThresholds = newCapture();
final FlowRuleOperations expectedOpsForCollector = FlowRuleOperations.builder().add(buildCollectorWatchlistRule(SPINE_DEVICE_ID)).build();
// Expected steps of method calls, captures, and results.
reset(driverData, hostService);
expect(driverData.deviceId()).andReturn(SPINE_DEVICE_ID).anyTimes();
expect(hostService.getHostsByIp(COLLECTOR_IP)).andReturn(ImmutableSet.of(collectorHost)).anyTimes();
expect(flowRuleService.getFlowEntriesById(APP_ID)).andReturn(ImmutableList.of()).times(3);
flowRuleService.apply(capture(capturedOpsForCollector));
flowRuleService.apply(capture(capturedOpsForSubnet));
flowRuleService.apply(capture(capturedOpsForQueueThresholds));
replay(driverData, hostService, flowRuleService);
// Verify values.
assertFalse(intProgrammable.setUpIntConfig(intConfig));
assertFlowRuleOperationsEquals(expectedOpsForCollector, capturedOpsForCollector.getValue());
assertFlowRuleOperationsEquals(EMPTY_FLOW_RULE_OPS, capturedOpsForSubnet.getValue());
verify(flowRuleService);
}
use of org.onosproject.net.DefaultHost in project onos by opennetworkinglab.
the class DistributedHostStore method removeLocation.
@Override
public void removeLocation(HostId hostId, HostLocation location) {
log.debug("Removing location {} from host {}", location, hostId);
hosts.compute(hostId, (id, existingHost) -> {
if (existingHost != null) {
checkState(Objects.equals(hostId.mac(), existingHost.mac()), "Existing and new MAC addresses differ.");
checkState(Objects.equals(hostId.vlanId(), existingHost.vlan()), "Existing and new VLANs differ.");
Set<HostLocation> locations = new HashSet<>(existingHost.locations());
locations.remove(location);
// Remove entire host if we are removing the last location
return locations.isEmpty() ? null : new DefaultHost(existingHost.providerId(), hostId, existingHost.mac(), existingHost.vlan(), locations, existingHost.auxLocations(), existingHost.ipAddresses(), existingHost.innerVlan(), existingHost.tpid(), existingHost.configured(), existingHost.suspended(), existingHost.annotations());
}
return null;
});
}
use of org.onosproject.net.DefaultHost in project onos by opennetworkinglab.
the class ObstacleConstraintTest method setUp.
@Before
public void setUp() {
resourceContext = createMock(ResourceContext.class);
link1 = DefaultLink.builder().providerId(PROVIDER_ID).src(cp(DID1, PN1)).dst(cp(DID2, PN2)).type(DIRECT).build();
link2 = DefaultLink.builder().providerId(PROVIDER_ID).src(cp(DID2, PN3)).dst(cp(DID3, PN4)).type(DIRECT).build();
host1 = new DefaultHost(PROVIDER_ID, HostId.hostId("00:00:00:00:00:01/None"), MacAddress.valueOf(0), VlanId.vlanId(), new HostLocation(DID5, PN1, 1), ImmutableSet.of(), DefaultAnnotations.EMPTY);
host2 = new DefaultHost(PROVIDER_ID, HostId.hostId("00:00:00:00:00:02/None"), MacAddress.valueOf(0), VlanId.vlanId(), new HostLocation(DID6, PN1, 1), ImmutableSet.of(), DefaultAnnotations.EMPTY);
edgelink1 = createEdgeLink(host1, true);
edgelink2 = createEdgeLink(host2, false);
path = new DefaultPath(PROVIDER_ID, Arrays.asList(link1, link2), ScalarWeight.toWeight(10));
pathWithEdgeLink = new DefaultPath(PROVIDER_ID, Arrays.asList(edgelink1, link1, link2, edgelink2), ScalarWeight.toWeight(10));
}
use of org.onosproject.net.DefaultHost in project onos by opennetworkinglab.
the class HostEventTest method createHost.
private Host createHost() {
MacAddress mac = MacAddress.valueOf("00:00:11:00:00:01");
VlanId vlan = VlanId.vlanId((short) 10);
HostLocation loc = new HostLocation(DeviceId.deviceId("of:foo"), PortNumber.portNumber(100), 123L);
Set<IpAddress> ipset = Sets.newHashSet(IpAddress.valueOf("10.0.0.1"), IpAddress.valueOf("10.0.0.2"));
HostId hid = HostId.hostId(mac, vlan);
return new DefaultHost(new ProviderId("of", "foo"), hid, mac, vlan, loc, ipset);
}
Aggregations