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