Search in sources :

Example 16 with DefaultHost

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

Example 17 with DefaultHost

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);
}
Also used : DefaultHost(org.onosproject.net.DefaultHost) FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) Host(org.onosproject.net.Host) DefaultHost(org.onosproject.net.DefaultHost) IntReportConfig(org.stratumproject.fabric.tna.inbandtelemetry.IntReportConfig) TestUtils.getIntReportConfig(org.stratumproject.fabric.tna.utils.TestUtils.getIntReportConfig) Test(org.junit.Test)

Example 18 with DefaultHost

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;
    });
}
Also used : DefaultHost(org.onosproject.net.DefaultHost) HostLocation(org.onosproject.net.HostLocation) HashSet(java.util.HashSet)

Example 19 with DefaultHost

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));
}
Also used : DefaultHost(org.onosproject.net.DefaultHost) ResourceContext(org.onosproject.net.intent.ResourceContext) HostLocation(org.onosproject.net.HostLocation) DefaultPath(org.onosproject.net.DefaultPath) Before(org.junit.Before)

Example 20 with DefaultHost

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);
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) DefaultHost(org.onosproject.net.DefaultHost) HostLocation(org.onosproject.net.HostLocation) IpAddress(org.onlab.packet.IpAddress) MacAddress(org.onlab.packet.MacAddress) HostId(org.onosproject.net.HostId) VlanId(org.onlab.packet.VlanId)

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