Search in sources :

Example 46 with DeviceService

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();
}
Also used : LinkKey(org.onosproject.net.LinkKey) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) DeviceService(org.onosproject.net.device.DeviceService) ConnectPoint(org.onosproject.net.ConnectPoint) Link(org.onosproject.net.Link) BasicLinkConfig(org.onosproject.net.config.basics.BasicLinkConfig)

Example 47 with DeviceService

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();
}
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 48 with DeviceService

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;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) LinkDescription(org.onosproject.net.link.LinkDescription) NetconfException(org.onosproject.netconf.NetconfException) Iterables(com.google.common.collect.Iterables) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) Device(org.onosproject.net.Device) DeviceService(org.onosproject.net.device.DeviceService) PORT_NAME(org.onosproject.net.AnnotationKeys.PORT_NAME) Set(java.util.Set) JuniperUtils.parseJuniperLldp(org.onosproject.drivers.juniper.JuniperUtils.parseJuniperLldp) AnnotationKeys(org.onosproject.net.AnnotationKeys) LinkDiscovery(org.onosproject.net.behaviour.LinkDiscovery) NetconfSession(org.onosproject.netconf.NetconfSession) Beta(com.google.common.annotations.Beta) REQ_LLDP_NBR_INFO(org.onosproject.drivers.juniper.JuniperUtils.REQ_LLDP_NBR_INFO) HashSet(java.util.HashSet) XmlConfigParser.loadXmlString(org.onosproject.drivers.utilities.XmlConfigParser.loadXmlString) Port(org.onosproject.net.Port) LinkAbstraction(org.onosproject.drivers.juniper.JuniperUtils.LinkAbstraction) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Optional(java.util.Optional) DeviceId(org.onosproject.net.DeviceId) JuniperUtils.requestBuilder(org.onosproject.drivers.juniper.JuniperUtils.requestBuilder) LinkDescription(org.onosproject.net.link.LinkDescription) DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService) XmlConfigParser.loadXmlString(org.onosproject.drivers.utilities.XmlConfigParser.loadXmlString) NetconfException(org.onosproject.netconf.NetconfException) LinkAbstraction(org.onosproject.drivers.juniper.JuniperUtils.LinkAbstraction) HashSet(java.util.HashSet)

Example 49 with DeviceService

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;
}
Also used : DeviceId(org.onosproject.net.DeviceId) Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 50 with DeviceService

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());
}
Also used : IntentService(org.onosproject.net.intent.IntentService) DeviceService(org.onosproject.net.device.DeviceService) OpticalIntentUtility.createOpticalIntent(org.onosproject.net.optical.util.OpticalIntentUtility.createOpticalIntent) Intent(org.onosproject.net.intent.Intent) ConnectPoint(org.onosproject.net.ConnectPoint)

Aggregations

DeviceService (org.onosproject.net.device.DeviceService)187 Device (org.onosproject.net.Device)75 DeviceId (org.onosproject.net.DeviceId)73 Port (org.onosproject.net.Port)59 ConnectPoint (org.onosproject.net.ConnectPoint)42 PortNumber (org.onosproject.net.PortNumber)40 List (java.util.List)30 Collectors (java.util.stream.Collectors)24 Set (java.util.Set)23 AbstractHandlerBehaviour (org.onosproject.net.driver.AbstractHandlerBehaviour)19 Logger (org.slf4j.Logger)19 ArrayList (java.util.ArrayList)18 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)17 Optional (java.util.Optional)17 Test (org.junit.Test)16 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 Collections (java.util.Collections)15 VirtualNetwork (org.onosproject.incubator.net.virtual.VirtualNetwork)15 DriverHandler (org.onosproject.net.driver.DriverHandler)15 Collection (java.util.Collection)14