Search in sources :

Example 6 with LinkService

use of org.onosproject.net.link.LinkService in project onos by opennetworkinglab.

the class AnnotateLinkCommand method doExecute.

@Override
protected void doExecute() {
    LinkService service = get(LinkService.class);
    ConnectPoint src = deviceConnectPoint(srcCp);
    ConnectPoint dst = deviceConnectPoint(dstCp);
    LinkProviderRegistry registry = get(LinkProviderRegistry.class);
    CliLinkProvider provider = new CliLinkProvider();
    LinkProviderService providerService = registry.register(provider);
    try {
        providerService.linkDetected(description(service.getLink(src, dst), key, value));
        if (both) {
            providerService.linkDetected(description(service.getLink(dst, src), key, value));
        }
    } finally {
        registry.unregister(provider);
    }
}
Also used : LinkProviderRegistry(org.onosproject.net.link.LinkProviderRegistry) LinkProviderService(org.onosproject.net.link.LinkProviderService) LinkService(org.onosproject.net.link.LinkService) ConnectPoint.deviceConnectPoint(org.onosproject.net.ConnectPoint.deviceConnectPoint) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 7 with LinkService

use of org.onosproject.net.link.LinkService in project onos by opennetworkinglab.

the class FlowRuleJuniperImpl method findIpDst.

/**
 * Helper method to find the next hop IP address.
 * The logic is to check if the destination ports have an IP address
 * by checking the logical interface (e.g., for port physical ge-2/0/1,
 * a logical interface may be ge-2/0/1.0
 *
 * @param deviceId the device id of the flow rule to be installed
 * @param port     output port of the flow rule treatment
 * @return optional IPv4 address of a next hop
 */
private Optional<Ip4Address> findIpDst(DeviceId deviceId, Port port) {
    LinkService linkService = this.handler().get(LinkService.class);
    Set<Link> links = linkService.getEgressLinks(new ConnectPoint(deviceId, port.number()));
    DeviceService deviceService = this.handler().get(DeviceService.class);
    // Using only links with adjacency discovered by the LLDP protocol (see LinkDiscoveryJuniperImpl)
    Map<DeviceId, Port> dstPorts = links.stream().filter(l -> JuniperUtils.AK_IP.toUpperCase().equals(l.annotations().value(AnnotationKeys.LAYER))).collect(Collectors.toMap(l -> l.dst().deviceId(), l -> deviceService.getPort(l.dst().deviceId(), l.dst().port())));
    for (Map.Entry<DeviceId, Port> entry : dstPorts.entrySet()) {
        String portName = entry.getValue().annotations().value(AnnotationKeys.PORT_NAME);
        Optional<Port> childPort = deviceService.getPorts(entry.getKey()).stream().filter(p -> Strings.nullToEmpty(p.annotations().value(AnnotationKeys.PORT_NAME)).contains(portName.trim())).filter(this::isIp).findAny();
        if (childPort.isPresent()) {
            return Optional.ofNullable(Ip4Address.valueOf(childPort.get().annotations().value(JuniperUtils.AK_IP)));
        }
    }
    return Optional.empty();
}
Also used : NetconfException(org.onosproject.netconf.NetconfException) StringUtils(org.apache.commons.lang.StringUtils) JuniperUtils.commitBuilder(org.onosproject.drivers.juniper.JuniperUtils.commitBuilder) FlowRuleProgrammable(org.onosproject.net.flow.FlowRuleProgrammable) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) FlowEntry(org.onosproject.net.flow.FlowEntry) AnnotationKeys(org.onosproject.net.AnnotationKeys) JuniperUtils.routeAddBuilder(org.onosproject.drivers.juniper.JuniperUtils.routeAddBuilder) Link(org.onosproject.net.Link) NetconfSession(org.onosproject.netconf.NetconfSession) ConnectPoint(org.onosproject.net.ConnectPoint) HashSet(java.util.HashSet) XmlConfigParser.loadXmlString(org.onosproject.drivers.utilities.XmlConfigParser.loadXmlString) Strings(com.google.common.base.Strings) FlowRuleService(org.onosproject.net.flow.FlowRuleService) JuniperUtils.routeDeleteBuilder(org.onosproject.drivers.juniper.JuniperUtils.routeDeleteBuilder) Port(org.onosproject.net.Port) Map(java.util.Map) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) Ip4Address(org.onlab.packet.Ip4Address) Instruction(org.onosproject.net.flow.instructions.Instruction) Collection(java.util.Collection) PENDING_REMOVE(org.onosproject.net.flow.FlowEntry.FlowEntryState.PENDING_REMOVE) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Set(java.util.Set) Collectors(java.util.stream.Collectors) ADD(org.onosproject.drivers.juniper.JuniperUtils.OperationType.ADD) REMOVED(org.onosproject.net.flow.FlowEntry.FlowEntryState.REMOVED) Beta(com.google.common.annotations.Beta) DatastoreId(org.onosproject.netconf.DatastoreId) OperationType(org.onosproject.drivers.juniper.JuniperUtils.OperationType) FlowRule(org.onosproject.net.flow.FlowRule) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) LinkService(org.onosproject.net.link.LinkService) Optional(java.util.Optional) REMOVE(org.onosproject.drivers.juniper.JuniperUtils.OperationType.REMOVE) DeviceId(org.onosproject.net.DeviceId) Collections(java.util.Collections) JuniperUtils.rollbackBuilder(org.onosproject.drivers.juniper.JuniperUtils.rollbackBuilder) DeviceId(org.onosproject.net.DeviceId) Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService) XmlConfigParser.loadXmlString(org.onosproject.drivers.utilities.XmlConfigParser.loadXmlString) ConnectPoint(org.onosproject.net.ConnectPoint) LinkService(org.onosproject.net.link.LinkService) Map(java.util.Map) Link(org.onosproject.net.Link)

Example 8 with LinkService

use of org.onosproject.net.link.LinkService in project onos by opennetworkinglab.

the class VirtualNetworkLinkManagerTest method testGetIngressLinksByNullId.

/**
 * Tests querying for ingress links using a null connect point.
 */
@Test(expected = NullPointerException.class)
public void testGetIngressLinksByNullId() {
    manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
    VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
    LinkService linkService = manager.get(virtualNetwork.id(), LinkService.class);
    // test the getIngressLinks() method with a null connect point.
    linkService.getIngressLinks(null);
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) LinkService(org.onosproject.net.link.LinkService) Test(org.junit.Test)

Example 9 with LinkService

use of org.onosproject.net.link.LinkService in project onos by opennetworkinglab.

the class VirtualNetworkLinkManagerTest method testGetLinkByNullDst.

/**
 * Tests the getLink() method using a null dst connect point.
 */
@Test(expected = NullPointerException.class)
public void testGetLinkByNullDst() {
    manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
    VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
    VirtualDevice srcVirtualDevice = manager.createVirtualDevice(virtualNetwork.id(), DID1);
    VirtualDevice dstVirtualDevice = manager.createVirtualDevice(virtualNetwork.id(), DID2);
    ConnectPoint src = new ConnectPoint(srcVirtualDevice.id(), PortNumber.portNumber(1));
    ConnectPoint dst = new ConnectPoint(dstVirtualDevice.id(), PortNumber.portNumber(2));
    manager.createVirtualLink(virtualNetwork.id(), src, dst);
    manager.createVirtualLink(virtualNetwork.id(), dst, src);
    LinkService linkService = manager.get(virtualNetwork.id(), LinkService.class);
    // test the getLink() method with a null dst connect point.
    linkService.getLink(src, null);
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) ConnectPoint(org.onosproject.net.ConnectPoint) LinkService(org.onosproject.net.link.LinkService) Test(org.junit.Test)

Example 10 with LinkService

use of org.onosproject.net.link.LinkService in project onos by opennetworkinglab.

the class VirtualNetworkLinkManagerTest method testGetLinkByNullSrc.

/**
 * Tests the getLink() method using a null src connect point.
 */
@Test(expected = NullPointerException.class)
public void testGetLinkByNullSrc() {
    manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
    VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
    VirtualDevice srcVirtualDevice = manager.createVirtualDevice(virtualNetwork.id(), DID1);
    VirtualDevice dstVirtualDevice = manager.createVirtualDevice(virtualNetwork.id(), DID2);
    ConnectPoint src = new ConnectPoint(srcVirtualDevice.id(), PortNumber.portNumber(1));
    ConnectPoint dst = new ConnectPoint(dstVirtualDevice.id(), PortNumber.portNumber(2));
    manager.createVirtualLink(virtualNetwork.id(), src, dst);
    manager.createVirtualLink(virtualNetwork.id(), dst, src);
    LinkService linkService = manager.get(virtualNetwork.id(), LinkService.class);
    // test the getLink() method with a null src connect point.
    linkService.getLink(null, dst);
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) ConnectPoint(org.onosproject.net.ConnectPoint) LinkService(org.onosproject.net.link.LinkService) Test(org.junit.Test)

Aggregations

LinkService (org.onosproject.net.link.LinkService)22 ConnectPoint (org.onosproject.net.ConnectPoint)12 Test (org.junit.Test)9 VirtualNetwork (org.onosproject.incubator.net.virtual.VirtualNetwork)9 Link (org.onosproject.net.Link)9 DeviceService (org.onosproject.net.device.DeviceService)5 Collectors (java.util.stream.Collectors)4 Collections (java.util.Collections)3 List (java.util.List)3 Set (java.util.Set)3 VirtualDevice (org.onosproject.incubator.net.virtual.VirtualDevice)3 DeviceId (org.onosproject.net.DeviceId)3 ImmutableList (com.google.common.collect.ImmutableList)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Optional (java.util.Optional)2 StringsCompleter (org.apache.karaf.shell.support.completers.StringsCompleter)2 ConnectPoint.deviceConnectPoint (org.onosproject.net.ConnectPoint.deviceConnectPoint)2