Search in sources :

Example 26 with ProviderId

use of org.onosproject.net.provider.ProviderId 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 27 with ProviderId

use of org.onosproject.net.provider.ProviderId in project onos by opennetworkinglab.

the class ECLinkStore method composeLink.

private Link composeLink(LinkKey linkKey) {
    ProviderId baseProviderId = getBaseProviderId(linkKey);
    if (baseProviderId == null) {
        // parent component.
        return null;
    }
    LinkDescription base = linkDescriptions.get(new Provided<>(linkKey, baseProviderId));
    // short circuit if link description no longer exists
    if (base == null) {
        return null;
    }
    ConnectPoint src = base.src();
    ConnectPoint dst = base.dst();
    Type type = base.type();
    DefaultAnnotations.Builder builder = DefaultAnnotations.builder();
    builder.putAll(base.annotations());
    getAllProviders(linkKey).stream().map(p -> new Provided<>(linkKey, p)).forEach(key -> {
        LinkDescription linkDescription = linkDescriptions.get(key);
        if (linkDescription != null) {
            builder.putAll(linkDescription.annotations());
        }
    });
    DefaultAnnotations annotations = builder.build();
    Link.State initialLinkState;
    boolean isExpected;
    if (linkDiscoveryMode == LinkDiscoveryMode.PERMISSIVE) {
        initialLinkState = ACTIVE;
        isExpected = Objects.equals(annotations.value(AnnotationKeys.DURABLE), "true");
    } else {
        initialLinkState = base.isExpected() ? ACTIVE : INACTIVE;
        isExpected = base.isExpected();
    }
    return DefaultLink.builder().providerId(baseProviderId).src(src).dst(dst).type(type).state(initialLinkState).isExpected(isExpected).annotations(annotations).build();
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) LINK_ADDED(org.onosproject.net.link.LinkEvent.Type.LINK_ADDED) NetworkConfigRegistry(org.onosproject.net.config.NetworkConfigRegistry) CoreService(org.onosproject.core.CoreService) APP_SUBJECT_FACTORY(org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FACTORY) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) Link(org.onosproject.net.Link) ConnectPoint(org.onosproject.net.ConnectPoint) LINK_REMOVED(org.onosproject.net.link.LinkEvent.Type.LINK_REMOVED) StorageService(org.onosproject.store.service.StorageService) INDIRECT(org.onosproject.net.Link.Type.INDIRECT) SharedExecutors(org.onlab.util.SharedExecutors) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) MessageSubject(org.onosproject.store.cluster.messaging.MessageSubject) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) ACTIVE(org.onosproject.net.Link.State.ACTIVE) MastershipService(org.onosproject.mastership.MastershipService) REMOVE(org.onosproject.store.service.EventuallyConsistentMapEvent.Type.REMOVE) DistributedStoreSerializers(org.onosproject.store.serializers.custom.DistributedStoreSerializers) LinkKey(org.onosproject.net.LinkKey) NodeId(org.onosproject.cluster.NodeId) DefaultLink(org.onosproject.net.DefaultLink) LinkDescription(org.onosproject.net.link.LinkDescription) Serializer(org.onosproject.store.service.Serializer) LinkStoreDelegate(org.onosproject.net.link.LinkStoreDelegate) EventuallyConsistentMapEvent(org.onosproject.store.service.EventuallyConsistentMapEvent) Deactivate(org.osgi.service.component.annotations.Deactivate) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) PUT(org.onosproject.store.service.EventuallyConsistentMapEvent.Type.PUT) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) ConfigFactory(org.onosproject.net.config.ConfigFactory) DeviceClockService(org.onosproject.net.device.DeviceClockService) ClusterCommunicationService(org.onosproject.store.cluster.messaging.ClusterCommunicationService) ClusterService(org.onosproject.cluster.ClusterService) DeviceId(org.onosproject.net.DeviceId) DIRECT(org.onosproject.net.Link.Type.DIRECT) Iterables(com.google.common.collect.Iterables) LinkEvent(org.onosproject.net.link.LinkEvent) NetworkConfigEvent(org.onosproject.net.config.NetworkConfigEvent) KryoNamespace(org.onlab.util.KryoNamespace) AnnotationKeys(org.onosproject.net.AnnotationKeys) AtomicReference(java.util.concurrent.atomic.AtomicReference) Component(org.osgi.service.component.annotations.Component) Activate(org.osgi.service.component.annotations.Activate) EventuallyConsistentMap(org.onosproject.store.service.EventuallyConsistentMap) EventuallyConsistentMapListener(org.onosproject.store.service.EventuallyConsistentMapListener) LinkKey.linkKey(org.onosproject.net.LinkKey.linkKey) LINK_UPDATED(org.onosproject.net.link.LinkEvent.Type.LINK_UPDATED) Logger(org.slf4j.Logger) INACTIVE(org.onosproject.net.Link.State.INACTIVE) ProviderId(org.onosproject.net.provider.ProviderId) MastershipBasedTimestamp(org.onosproject.store.impl.MastershipBasedTimestamp) DefaultAnnotations.union(org.onosproject.net.DefaultAnnotations.union) Maps(com.google.common.collect.Maps) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) Futures(com.google.common.util.concurrent.Futures) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) AnnotationsUtil(org.onosproject.net.AnnotationsUtil) AbstractStore(org.onosproject.store.AbstractStore) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) LinkStore(org.onosproject.net.link.LinkStore) Reference(org.osgi.service.component.annotations.Reference) NetworkConfigListener(org.onosproject.net.config.NetworkConfigListener) Type(org.onosproject.net.Link.Type) Type(org.onosproject.net.Link.Type) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) LinkDescription(org.onosproject.net.link.LinkDescription) ConnectPoint(org.onosproject.net.ConnectPoint) Link(org.onosproject.net.Link) DefaultLink(org.onosproject.net.DefaultLink)

Example 28 with ProviderId

use of org.onosproject.net.provider.ProviderId in project onos by opennetworkinglab.

the class ECLinkStore method injectLink.

private LinkEvent injectLink(Provided<LinkDescription> linkInjectRequest) {
    log.trace("Received request to inject link {}", linkInjectRequest);
    ProviderId providerId = linkInjectRequest.providerId();
    LinkDescription linkDescription = linkInjectRequest.key();
    final DeviceId deviceId = linkDescription.dst().deviceId();
    if (!deviceClockService.isTimestampAvailable(deviceId)) {
        // workaround for ONOS-1208
        log.warn("Not ready to accept update. Dropping {}", linkInjectRequest);
        return null;
    }
    return createOrUpdateLink(providerId, linkDescription);
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) LinkDescription(org.onosproject.net.link.LinkDescription) DeviceId(org.onosproject.net.DeviceId)

Example 29 with ProviderId

use of org.onosproject.net.provider.ProviderId in project onos by opennetworkinglab.

the class DefaultTunnelTest method testEquality.

@Test
public void testEquality() {
    TunnelEndPoint src = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(23423));
    TunnelEndPoint dst = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(32421));
    GroupId groupId = new GroupId(92034);
    TunnelName tunnelName = TunnelName.tunnelName("TunnelName");
    TunnelId tunnelId = TunnelId.valueOf("41654654");
    ProviderId producerName1 = new ProviderId("producer1", "13");
    ProviderId producerName2 = new ProviderId("producer2", "13");
    Tunnel p1 = new DefaultTunnel(producerName1, src, dst, Tunnel.Type.VXLAN, Tunnel.State.ACTIVE, groupId, tunnelId, tunnelName, null);
    Tunnel p2 = new DefaultTunnel(producerName1, src, dst, Tunnel.Type.VXLAN, Tunnel.State.ACTIVE, groupId, tunnelId, tunnelName, null);
    Tunnel p3 = new DefaultTunnel(producerName2, src, dst, Tunnel.Type.OCH, Tunnel.State.ACTIVE, groupId, tunnelId, tunnelName, null);
    new EqualsTester().addEqualityGroup(p1, p2).addEqualityGroup(p3).testEquals();
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) EqualsTester(com.google.common.testing.EqualsTester) GroupId(org.onosproject.core.GroupId) Test(org.junit.Test)

Example 30 with ProviderId

use of org.onosproject.net.provider.ProviderId in project onos by opennetworkinglab.

the class TunnelEventTest method testConstructor.

/**
 * Checks the operation of equals(), hashCode() and toString() methods.
 */
@Test
public void testConstructor() {
    TunnelEndPoint src = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(23423));
    TunnelEndPoint dst = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(32421));
    GroupId groupId = new GroupId(92034);
    TunnelName tunnelName = TunnelName.tunnelName("TunnelName");
    TunnelId tunnelId = TunnelId.valueOf("41654654");
    ProviderId producerName1 = new ProviderId("producer1", "13");
    Tunnel p1 = new DefaultTunnel(producerName1, src, dst, Tunnel.Type.VXLAN, Tunnel.State.ACTIVE, groupId, tunnelId, tunnelName, null);
    TunnelEvent e1 = new TunnelEvent(TunnelEvent.Type.TUNNEL_ADDED, p1);
    assertThat(e1, is(notNullValue()));
    assertThat(e1.type(), is(TunnelEvent.Type.TUNNEL_ADDED));
    assertThat(e1.subject(), is(p1));
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) GroupId(org.onosproject.core.GroupId) Test(org.junit.Test)

Aggregations

ProviderId (org.onosproject.net.provider.ProviderId)62 DefaultDevice (org.onosproject.net.DefaultDevice)15 DeviceId (org.onosproject.net.DeviceId)13 Tunnel (org.onosproject.incubator.net.tunnel.Tunnel)12 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)12 Device (org.onosproject.net.Device)12 PortDescription (org.onosproject.net.device.PortDescription)12 TunnelProvider (org.onosproject.incubator.net.tunnel.TunnelProvider)10 DefaultPort (org.onosproject.net.DefaultPort)10 Port (org.onosproject.net.Port)10 DeviceEvent (org.onosproject.net.device.DeviceEvent)10 MastershipBasedTimestamp (org.onosproject.store.impl.MastershipBasedTimestamp)10 PortNumber (org.onosproject.net.PortNumber)9 DeviceDescription (org.onosproject.net.device.DeviceDescription)9 Timestamp (org.onosproject.store.Timestamp)9 MultiValuedTimestamp (org.onosproject.store.service.MultiValuedTimestamp)9 WallClockTimestamp (org.onosproject.store.service.WallClockTimestamp)9 DefaultTunnel (org.onosproject.incubator.net.tunnel.DefaultTunnel)7 TunnelId (org.onosproject.incubator.net.tunnel.TunnelId)7 DefaultLinkDescription (org.onosproject.net.link.DefaultLinkDescription)7