use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.
the class ConfigureLinkCommand method doExecute.
@Override
protected void doExecute() {
DeviceService deviceService = get(DeviceService.class);
NetworkConfigService netCfgService = get(NetworkConfigService.class);
ConnectPoint srcCp = ConnectPoint.deviceConnectPoint(src);
if (deviceService.getPort(srcCp) == null) {
print("[ERROR] %s does not exist", srcCp);
return;
}
ConnectPoint dstCp = ConnectPoint.deviceConnectPoint(dst);
if (deviceService.getPort(dstCp) == null) {
print("[ERROR] %s does not exist", dstCp);
return;
}
LinkKey link = linkKey(srcCp, dstCp);
if (remove) {
netCfgService.removeConfig(link, BasicLinkConfig.class);
return;
}
Long bw = Optional.ofNullable(bandwidth).map(Long::valueOf).orElse(null);
Link.Type linkType = Link.Type.valueOf(type);
BasicLinkConfig cfg = netCfgService.addConfig(link, BasicLinkConfig.class);
cfg.isAllowed(!disallow);
cfg.isBidirectional(!isUniDi);
cfg.type(linkType);
if (bw != null) {
cfg.bandwidth(bw);
}
cfg.apply();
}
use of org.onosproject.net.device.DeviceService 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.device.DeviceService in project onos by opennetworkinglab.
the class LinkDiscoveryJuniperImpl method getLinks.
@Override
public Set<LinkDescription> getLinks() {
DeviceId localDeviceId = this.handler().data().deviceId();
NetconfSession session = lookupNetconfSession(localDeviceId);
String reply;
try {
reply = session.get(requestBuilder(REQ_LLDP_NBR_INFO));
} catch (NetconfException e) {
log.warn("Failed to retrieve lldp-neighbors-information for device {}", localDeviceId);
return ImmutableSet.of();
}
log.debug("Reply from device {} : {}", localDeviceId, reply);
Set<LinkAbstraction> linkAbstractions = parseJuniperLldp(loadXmlString(reply));
log.debug("Set of LinkAbstraction discovered {}", linkAbstractions);
DeviceService deviceService = this.handler().get(DeviceService.class);
Set<LinkDescription> descriptions = new HashSet<>();
// for each lldp neighbor create two LinkDescription
for (LinkAbstraction linkAbs : linkAbstractions) {
// find source port by local port name
Optional<Port> localPort = deviceService.getPorts(localDeviceId).stream().filter(port -> linkAbs.localPortName.equals(port.annotations().value(PORT_NAME))).findAny();
if (!localPort.isPresent()) {
log.warn("Port name {} does not exist in device {}", linkAbs.localPortName, localDeviceId);
continue;
}
// find destination device by remote chassis id
com.google.common.base.Optional<Device> dev = Iterables.tryFind(deviceService.getAvailableDevices(), input -> input.chassisId().equals(linkAbs.remoteChassisId));
if (!dev.isPresent()) {
log.warn("Device with chassis ID {} does not exist. Referenced by {}/{}", linkAbs.remoteChassisId, localDeviceId, linkAbs);
continue;
}
Device remoteDevice = dev.get();
// find destination port by interface index
Optional<Port> remotePort = deviceService.getPorts(remoteDevice.id()).stream().filter(port -> {
if (port.number().toLong() == linkAbs.remotePortIndex) {
return true;
}
if (port.annotations().value(AnnotationKeys.PORT_MAC) != null && linkAbs.remotePortId != null && port.annotations().value(AnnotationKeys.PORT_MAC).equals(linkAbs.remotePortId)) {
return true;
}
if (port.annotations().value(AnnotationKeys.PORT_NAME) != null && linkAbs.remotePortId != null && port.annotations().value(AnnotationKeys.PORT_NAME).equals(linkAbs.remotePortId)) {
return true;
}
if (port.annotations().value(AnnotationKeys.PORT_NAME) != null && linkAbs.remotePortDescription != null && port.annotations().value(AnnotationKeys.PORT_NAME).equals(linkAbs.remotePortDescription)) {
return true;
}
return false;
}).findAny();
if (!remotePort.isPresent()) {
log.warn("Port does not exist in remote device {}. Referenced by {}/{}", remoteDevice.id(), localDeviceId, linkAbs);
continue;
}
if (!localPort.get().isEnabled() || !remotePort.get().isEnabled()) {
log.debug("Ports are disabled. Cannot create a link between {}/{} and {}/{}", localDeviceId, localPort.get(), remoteDevice.id(), remotePort.get());
continue;
}
JuniperUtils.createOneWayLinkDescription(localDeviceId, localPort.get(), remoteDevice.id(), remotePort.get(), descriptions);
}
return descriptions;
}
use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.
the class AddOpticalIntentCommand method createConnectPoint.
private ConnectPoint createConnectPoint(String devicePortString) {
String[] splitted = devicePortString.split("/");
checkArgument(splitted.length == 2, "Connect point must be in \"deviceUri/portNumber\" format");
DeviceId deviceId = DeviceId.deviceId(splitted[0]);
DeviceService deviceService = get(DeviceService.class);
List<Port> ports = deviceService.getPorts(deviceId);
for (Port port : ports) {
if (splitted[1].equals(port.number().name())) {
return new ConnectPoint(deviceId, port.number());
}
}
return null;
}
use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.
the class AddOpticalIntentCommand method doExecute.
@Override
protected void doExecute() {
IntentService service = get(IntentService.class);
DeviceService deviceService = get(DeviceService.class);
ConnectPoint ingress = createConnectPoint(ingressString);
ConnectPoint egress = createConnectPoint(egressString);
Intent intent = createOpticalIntent(ingress, egress, deviceService, key(), appId(), bidirectional, createOchSignal(), null);
service.submit(intent);
print("Optical intent submitted:\n%s", intent.toString());
}
Aggregations