org.onosproject.net.PortNumber Java Examples

The following examples show how to use org.onosproject.net.PortNumber. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClassifierServiceImpl.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void programArpClassifierRules(DeviceId deviceId, PortNumber inPort,
                                      IpAddress dstIp,
                                      SegmentationId actionVni,
                                      Objective.Operation type) {
    TrafficSelector selector = DefaultTrafficSelector.builder()
            .matchInPort(inPort).matchEthType(ETH_TYPE.ethType().toShort())
            .matchArpTpa(Ip4Address.valueOf(dstIp.toString())).build();
    TrafficTreatment treatment = DefaultTrafficTreatment.builder()
            .setTunnelId(Long.parseLong(actionVni.segmentationId()))
            .build();
    ForwardingObjective.Builder objective = DefaultForwardingObjective
            .builder().withTreatment(treatment).withSelector(selector)
            .fromApp(appId).withFlag(Flag.SPECIFIC)
            .withPriority(ARP_CLASSIFIER_PRIORITY);
    if (type.equals(Objective.Operation.ADD)) {
        log.debug("ArpClassifierRules-->ADD");
        flowObjectiveService.forward(deviceId, objective.add());
    } else {
        log.debug("ArpClassifierRules-->REMOVE");
        flowObjectiveService.forward(deviceId, objective.remove());
    }
}
 
Example #2
Source File: DefaultTributarySlotQuery.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public Set<TributarySlot> queryTributarySlots(PortNumber port) {
    // currently return all slots by default.
    DeviceService deviceService = opticalView(this.handler().get(DeviceService.class));
    Port p = deviceService.getPort(this.data().deviceId(), port);

    if (p == null) {
        return Collections.emptySet();
    }

    switch (p.type()) {
        case OCH:
            return queryOchTributarySlots(p);
        case OTU:
            return queryOtuTributarySlots(p);
        default:
            return Collections.emptySet();
    }
}
 
Example #3
Source File: VirtualNetworkManagerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Tests adding the same virtual link twice.
 */
@Test(expected = IllegalStateException.class)
public void testAddSameVirtualLink() {
    manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
    VirtualNetwork virtualNetwork1 =
            manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
    VirtualDevice srcVirtualDevice =
            manager.createVirtualDevice(virtualNetwork1.id(), DID1);
    VirtualDevice dstVirtualDevice =
            manager.createVirtualDevice(virtualNetwork1.id(), DID2);
    ConnectPoint src = new ConnectPoint(srcVirtualDevice.id(), PortNumber.portNumber(1));
    manager.createVirtualPort(virtualNetwork1.id(), src.deviceId(), src.port(),
                              new ConnectPoint(srcVirtualDevice.id(), src.port()));

    ConnectPoint dst = new ConnectPoint(dstVirtualDevice.id(), PortNumber.portNumber(2));
    manager.createVirtualPort(virtualNetwork1.id(), dst.deviceId(), dst.port(),
                              new ConnectPoint(dstVirtualDevice.id(), dst.port()));

    manager.createVirtualLink(virtualNetwork1.id(), src, dst);
    manager.createVirtualLink(virtualNetwork1.id(), src, dst);
}
 
Example #4
Source File: OchPortHelper.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Creates OCh port DefaultPortDescription based on the supplied information.
 *
 * @param number      port number
 * @param isEnabled   port enabled state
 * @param signalType  ODU signal type
 * @param isTunable   tunable wavelength capability
 * @param lambda      OCh signal
 * @param annotationsIn key/value annotations map
 * @return OCh port DefaultPortDescription with OCh annotations
 */
public static PortDescription ochPortDescription(PortNumber number,
                                                 boolean isEnabled,
                                                 OduSignalType signalType,
                                                 boolean isTunable,
                                                 OchSignal lambda,
                                                 SparseAnnotations annotationsIn) {

    Builder builder = DefaultAnnotations.builder();
    builder.putAll(annotationsIn);

    builder.set(TUNABLE, String.valueOf(isTunable));
    builder.set(LAMBDA, OchSignalCodec.encode(lambda).toString());
    builder.set(SIGNAL_TYPE, signalType.toString());

    DefaultAnnotations annotations = builder.build();
    long portSpeed = signalType.bitRate();
    return DefaultPortDescription.builder().withPortNumber(number).isEnabled(isEnabled)
            .type(Port.Type.OCH).portSpeed(portSpeed).annotations(annotations)
            .build();
}
 
Example #5
Source File: RoadmPortViewMessageHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void process(ObjectNode payload) {
    DeviceId deviceId = DeviceId.deviceId(string(payload, RoadmUtil.DEV_ID));
    PortNumber portNumber = PortNumber.portNumber(payload.get(ID).asLong());
    Range<Double> range = roadmService.targetPortPowerRange(deviceId, portNumber);
    if (range == null) {
        log.warn("Unable to determine target power range for device {}", deviceId);
        return;
    }
    Double targetPower = payload.get(TARGET_POWER).asDouble();
    boolean validTargetPower = range.contains(targetPower);
    if (validTargetPower) {
        roadmService.setTargetPortPower(deviceId, portNumber, targetPower);
    }
    ObjectNode rootNode = objectNode();
    rootNode.put(ID, payload.get(ID).asText());
    rootNode.put(RoadmUtil.VALID, validTargetPower);
    rootNode.put(RoadmUtil.MESSAGE, String.format(TARGET_POWER_ERR_MSG, range.toString()));
    sendMessage(ROADM_SET_TARGET_POWER_RESP, rootNode);
}
 
Example #6
Source File: OtuPortHelper.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Creates OTU port description based on the supplied information.
 *
 * @param number        port number
 * @param isEnabled     port enabled state
 * @param signalType    OTU client signal type
 * @param annotations   key/value annotations map
 * @return              port description
 */
public static PortDescription otuPortDescription(PortNumber number,
                                                 boolean isEnabled,
                                                 OtuSignalType signalType,
                                                 SparseAnnotations annotations) {
    Builder builder = DefaultAnnotations.builder();
    builder.putAll(annotations);

    builder.set(SIGNAL_TYPE, signalType.toString());

    long portSpeed = 0; // TODO specify appropriate value?
    return DefaultPortDescription.builder()
            .withPortNumber(number)
            .isEnabled(isEnabled)
            .type(Port.Type.OTU)
            .portSpeed(portSpeed)
            .annotations(builder.build())
            .build();
}
 
Example #7
Source File: PacketLinkRealizedByOpticalTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Checks the construction of OpticalConnectivityId object with OpticalConnectivityIntent.
 */
@Test
public void testCreateWithConnectivityIntent() {
    ConnectPoint cp1 = new ConnectPoint(DeviceId.deviceId("of:0000000000000001"), PortNumber.portNumber(1L));
    ConnectPoint cp2 = new ConnectPoint(DeviceId.deviceId("of:0000000000000002"), PortNumber.portNumber(2L));
    OpticalConnectivityIntent connIntent = OpticalConnectivityIntent.builder()
            .appId(appId)
            .src(cp1)
            .dst(cp2)
            .bidirectional(true)
            .key(Key.of(0, appId))
            .signalType(OduSignalType.ODU4)
            .build();

    PacketLinkRealizedByOptical plink = PacketLinkRealizedByOptical.create(cp1, cp2, connIntent);

    assertNotNull(plink);
    assertEquals(plink.src(), cp1);
    assertEquals(plink.dst(), cp2);
    assertEquals((long) plink.bandwidth().bps(), OduSignalType.ODU4.bitRate());
}
 
Example #8
Source File: IsisTopologyProvider.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void addLink(IsisLink isisLink) {
    log.debug("Addlink {}", isisLink.localSystemId());

    LinkDescription linkDes = buildLinkDes(isisLink);
    //Updating ports of the link
    //If already link exists, return
    if (linkService.getLink(linkDes.src(), linkDes.dst()) != null || linkProviderService == null) {
        return;
    }
    ConnectPoint destconnectPoint = linkDes.dst();
    PortNumber destport = destconnectPoint.port();
    if (destport.toLong() != 0) {
        deviceProviderService.updatePorts(linkDes.src().deviceId(),
                                          buildPortDescriptions(linkDes.src().deviceId(),
                                          linkDes.src().port()));
        deviceProviderService.updatePorts(linkDes.dst().deviceId(),
                                          buildPortDescriptions(linkDes.dst().deviceId(),
                                          linkDes.dst().port()));
        registerBandwidth(linkDes, isisLink);
        linkProviderService.linkDetected(linkDes);
        System.out.println("link desc " + linkDes.toString());
    }
}
 
Example #9
Source File: Ciena5162PortAdmin.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public CompletableFuture<Boolean> isEnabled(PortNumber number) {
    NetconfController controller = checkNotNull(handler().get(NetconfController.class));
    NetconfSession session = controller.getDevicesMap().get(handler().data().deviceId()).getSession();

    try {
        Map<String, Object> templateContext = new HashMap<String, Object>();
        templateContext.put("port-number", number.toString());
        Node port = TEMPLATE_MANAGER.doRequest(session, "logicalPort", templateContext);
        XPath xp = XPathFactory.newInstance().newXPath();
        return CompletableFuture.completedFuture(Boolean.valueOf(xp.evaluate("admin-status/text()", port)));
    } catch (XPathExpressionException | NetconfException e) {
        log.error("Unable to query port state for port {} from device {}", number, handler().data().deviceId(), e);
    }
    return CompletableFuture.completedFuture(false);
}
 
Example #10
Source File: ScaleTestManager.java    From onos with Apache License 2.0 6 votes vote down vote up
private void addMoreFlows(int flowsPerDevice, Device device, DeviceId id,
                          int currentFlowCount) {
    int c = flowsPerDevice - currentFlowCount;
    log.info("Adding {} flows for device {}", c, id);
    List<PortNumber> ports = devicePorts(device);
    FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
    for (int i = 0; i < c; i++) {
        FlowRule.Builder frb = DefaultFlowRule.builder();
        frb.fromApp(appId).makePermanent().withPriority((currentFlowCount + i) % FlowRule.MAX_PRIORITY);
        TrafficSelector.Builder tsb = DefaultTrafficSelector.builder();
        TrafficTreatment.Builder ttb = DefaultTrafficTreatment.builder();

        tsb.matchEthType(Ethernet.TYPE_IPV4);
        tsb.matchEthDst(randomMac());
        ttb.setEthDst(randomMac()).setEthSrc(randomMac());
        ttb.setOutput(randomPort(ports));
        frb.withSelector(tsb.build()).withTreatment(ttb.build());
        ops.add(frb.forDevice(id).build());
    }
    flowRuleService.apply(ops.build());
}
 
Example #11
Source File: OFOpticalSwitch13LambdaQuery.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public Set<OchSignal> queryLambdas(PortNumber port) {
    DeviceService deviceService = opticalView(this.handler().get(DeviceService.class));
    Port p = deviceService.getPort(this.data().deviceId(), port);

    // Only OMS ports expose lambda resources
    if (p == null || !p.type().equals(Port.Type.OMS)) {
        return Collections.emptySet();
    }

    short lambdaCount = ((OmsPort) p).totalChannels();
    // OMS ports expose 'lambdaCount' fixed grid lambdas of 50GHz width, starting from min-frequency 191.7 THz.
    return IntStream.rangeClosed(1, lambdaCount)
            .mapToObj(x -> OchSignal.newDwdmSlot(ChannelSpacing.CHL_50GHZ, x))
            .collect(GuavaCollectors.toImmutableSet());
}
 
Example #12
Source File: SimpleDeviceStore.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a Port, merging description given from multiple Providers.
 *
 * @param device   device the port is on
 * @param number   port number
 * @param descsMap Collection of Descriptions from multiple providers
 * @return Port instance
 */
private Port composePort(Device device, PortNumber number,
                         Map<ProviderId, DeviceDescriptions> descsMap) {

    ProviderId primary = pickPrimaryPid(descsMap);
    DeviceDescriptions primDescs = descsMap.get(primary);
    // if no primary, assume not enabled
    // TODO: revisit this default port enabled/disabled behavior
    boolean isEnabled = false;
    DefaultAnnotations annotations = DefaultAnnotations.builder().build();

    final PortDescription portDesc = primDescs.getPortDesc(number);
    if (portDesc != null) {
        isEnabled = portDesc.isEnabled();
        annotations = merge(annotations, portDesc.annotations());
    }

    for (Entry<ProviderId, DeviceDescriptions> e : descsMap.entrySet()) {
        if (e.getKey().equals(primary)) {
            continue;
        }
        // TODO: should keep track of Description timestamp
        // and only merge conflicting keys when timestamp is newer
        // Currently assuming there will never be a key conflict between
        // providers

        // annotation merging. not so efficient, should revisit later
        final PortDescription otherPortDesc = e.getValue().getPortDesc(number);
        if (otherPortDesc != null) {
            annotations = merge(annotations, otherPortDesc.annotations());
        }
    }

    return portDesc == null ?
            new DefaultPort(device, number, false, annotations) :
            new DefaultPort(device, number, isEnabled, portDesc.type(),
                            portDesc.portSpeed(), annotations);
}
 
Example #13
Source File: DeviceEventTest.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
@Test
public void withTime() {
    Device device = createDevice();
    Port port = new DefaultPort(device, PortNumber.portNumber(123), true);
    DeviceEvent event = new DeviceEvent(DeviceEvent.Type.DEVICE_ADDED,
            device, port, 123L);
    validateEvent(event, DeviceEvent.Type.DEVICE_ADDED, device, 123L);
    assertEquals("incorrect port", port, event.port());
}
 
Example #14
Source File: RoadmPortViewMessageHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
private String getCurrentInputPower(DeviceId deviceId, PortNumber portNumber) {
    PowerConfig powerConfig = deviceService.getDevice(deviceId).as(PowerConfig.class);
    Optional<Double> currentInputPower = powerConfig.currentInputPower(portNumber, Direction.ALL);
    Double inputPowerVal = null;
    if (currentInputPower.isPresent()) {
        inputPowerVal = currentInputPower.orElse(Double.MIN_VALUE);
    }
    return RoadmUtil.objectToString(inputPowerVal, RoadmUtil.UNKNOWN);
}
 
Example #15
Source File: PolatisPowerConfig.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public Optional<Double> currentPower(PortNumber port, T component) {
    Long power = acquireCurrentPower(port, component);
    if (power == null) {
        return Optional.empty();
    }
    return Optional.of(power.doubleValue());
}
 
Example #16
Source File: OplinkPowerConfigUtil.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Sets specified port target power or channel attenuation.
 *
 * @param port the port number
 * @param component the port component
 * @param power target power in .01 dBm
 */
public void setTargetPower(PortNumber port, Object component, long power) {
    switch (getComponentType(component)) {
        case PORT:
            setPortPower(port, power);
            break;
        case CHANNEL:
            setChannelAttenuation(port, (OchSignal) component, power);
           break;
        default:
            break;
    }
}
 
Example #17
Source File: PolatisPowerConfig.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Get the filter string for the OPM power NETCONF request.
 *
 * @param port the port, null to return all the opm ports
 * @return filter string
 */
private String getPortPowerFilter(PortNumber port) {
    StringBuilder filter = new StringBuilder(xmlOpen(KEY_OPM_XMLNS))
            .append(xmlOpen(KEY_PORT))
            .append(xmlOpen(KEY_PORTID));
    if (port != null) {
        filter.append(port.toLong());
    }
    return filter.append(xmlClose(KEY_PORTID))
            .append(xmlClose(KEY_PORT))
            .append(xmlClose(KEY_OPM))
            .toString();
}
 
Example #18
Source File: FabricIntProgrammable.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public boolean setSinkPort(PortNumber port) {

    if (!setupBehaviour()) {
        return false;
    }

    PiCriterion egressCriterion = PiCriterion.builder()
            .matchExact(FabricConstants.HDR_EG_PORT, port.toLong())
            .build();
    TrafficSelector sinkSelector = DefaultTrafficSelector.builder()
            .matchPi(egressCriterion)
            .build();
    PiAction setSinkAct = PiAction.builder()
            .withId(FabricConstants.FABRIC_INGRESS_PROCESS_SET_SOURCE_SINK_INT_SET_SINK)
            .build();
    TrafficTreatment sinkTreatment = DefaultTrafficTreatment.builder()
            .piTableAction(setSinkAct)
            .build();
    FlowRule sinkFlowRule = DefaultFlowRule.builder()
            .withSelector(sinkSelector)
            .withTreatment(sinkTreatment)
            .fromApp(appId)
            .withPriority(DEFAULT_PRIORITY)
            .makePermanent()
            .forDevice(deviceId)
            .forTable(FabricConstants.FABRIC_INGRESS_PROCESS_SET_SOURCE_SINK_TB_SET_SINK)
            .build();
    flowRuleService.applyFlowRules(sinkFlowRule);
    return true;
}
 
Example #19
Source File: PolatisPowerConfig.java    From onos with Apache License 2.0 5 votes vote down vote up
private Long acquireCurrentPower(PortNumber port, T component) {
    if (component instanceof OchSignal) {
        log.warn("Channel power is not applicable.");
        return null;
    }
    log.debug("Get port{} current power...", port);
    return acquirePortPower(port);
}
 
Example #20
Source File: DefaultGroupHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a single port to the L2FG or removes it from the L2FG.
 *
 * @param vlanId the vlan id corresponding to this port
 * @param portNum the port on this device to be updated
 * @param nextId the next objective ID for the given vlan id
 * @param install if true, adds the port to L2FG. If false, removes it from L2FG.
 */
public void updateGroupFromVlanConfiguration(VlanId vlanId, PortNumber portNum, int nextId, boolean install) {
    TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
    if (toPopVlan(portNum, vlanId)) {
        tBuilder.popVlan();
    }
    tBuilder.setOutput(portNum);

    TrafficSelector metadata =
            DefaultTrafficSelector.builder().matchVlanId(vlanId).build();

    NextObjective.Builder nextObjBuilder = DefaultNextObjective
            .builder().withId(nextId)
            .withType(NextObjective.Type.BROADCAST).fromApp(appId)
            .addTreatment(tBuilder.build())
            .withMeta(metadata);

    ObjectiveContext context = new DefaultObjectiveContext(
            (objective) -> log.debug("port {} successfully removedFrom NextObj {} on {}",
                                     portNum, nextId, deviceId),
            (objective, error) -> {
                log.warn("port {} failed to removedFrom NextObj {} on {}: {}", portNum, nextId, deviceId, error);
                srManager.invalidateNextObj(objective.id());
            });

    if (install) {
        flowObjectiveService.next(deviceId, nextObjBuilder.addToExisting(context));
    } else {
        flowObjectiveService.next(deviceId, nextObjBuilder.removeFromExisting(context));
    }
}
 
Example #21
Source File: SfcFlowRuleInstallerImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
private PortNumber getVxlanPortNumber(DeviceId deviceId) {
    Iterable<Port> ports = deviceService.getPorts(deviceId);
    Port vxlanPort = Sets.newHashSet(ports).stream()
            .filter(p -> !p.number().equals(PortNumber.LOCAL))
            .filter(p -> p.annotations().value(AnnotationKeys.PORT_NAME)
                    .startsWith(VXLANPORT_HEAD))
            .findFirst().get();
    return vxlanPort.number();
}
 
Example #22
Source File: FabricFilteringPipelinerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
private FlowRule buildExpectedVlanInPortRule(PortNumber inPort,
                                             VlanId vlanId,
                                             VlanId innerVlanId,
                                             VlanId internalVlan,
                                             TableId tableId) {

    TrafficSelector.Builder selector = DefaultTrafficSelector.builder()
            .matchInPort(inPort);
    PiAction piAction;
    selector.matchPi(buildPiCriterionVlan(vlanId, innerVlanId));
    if (!vlanValid(vlanId)) {
        piAction = PiAction.builder()
                .withId(FabricConstants.FABRIC_INGRESS_FILTERING_PERMIT_WITH_INTERNAL_VLAN)
                .withParameter(new PiActionParam(
                        FabricConstants.VLAN_ID, internalVlan.toShort()))
                .build();
    } else {
        selector.matchVlanId(vlanId);
        if (vlanValid(innerVlanId)) {
            selector.matchInnerVlanId(innerVlanId);
        }
        piAction = PiAction.builder()
                .withId(FabricConstants.FABRIC_INGRESS_FILTERING_PERMIT)
                .build();
    }

    return DefaultFlowRule.builder()
            .withPriority(PRIORITY)
            .withSelector(selector.build())
            .withTreatment(DefaultTrafficTreatment.builder()
                                   .piTableAction(piAction).build())
            .fromApp(APP_ID)
            .forDevice(DEVICE_ID)
            .makePermanent()
            .forTable(tableId)
            .build();
}
 
Example #23
Source File: RoadmPortViewMessageHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
private String getTargetPower(DeviceId deviceId, PortNumber portNumber) {
    if (!roadmService.hasPortTargetPower(deviceId, portNumber)) {
        return RoadmUtil.NA;
    }
    Double targetPower = roadmService.getTargetPortPower(deviceId, portNumber);
    return RoadmUtil.objectToString(targetPower, RoadmUtil.UNKNOWN);
}
 
Example #24
Source File: VirtualNetworkTopologyManagerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Test isBroadcastPoint() method.
 */
@Test
public void testIsBroadcastPoint() {
    VirtualNetwork virtualNetwork = setupVirtualNetworkTopology();

    TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class);
    Topology topology = topologyService.currentTopology();

    VirtualDevice srcVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID1);
    ConnectPoint cp = new ConnectPoint(srcVirtualDevice.id(), PortNumber.portNumber(1));

    // test the isBroadcastPoint() method.
    Boolean isBroadcastPoint = topologyService.isBroadcastPoint(topology, cp);
    assertTrue("The connect point should be a broadcast point.", isBroadcastPoint);
}
 
Example #25
Source File: DevicesWebResource.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Changes the administrative state of a port.
 *
 * @onos.rsModel PortAdministrativeState
 * @param id device identifier
 * @param portId port number
 * @param stream input JSON
 * @return 200 OK if the port state was set to the given value
 */
@POST
@Path("{id}/portstate/{port_id}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response setPortState(@PathParam("id") String id,
                             @PathParam("port_id") String portId,
                             InputStream stream) {
    try {
        DeviceId deviceId = deviceId(id);
        PortNumber portNumber = PortNumber.portNumber(portId);
        nullIsNotFound(get(DeviceService.class).getPort(
                new ConnectPoint(deviceId, portNumber)), DEVICE_NOT_FOUND);

        ObjectNode root = readTreeFromStream(mapper(), stream);
        JsonNode node = root.path(ENABLED);

        if (!node.isMissingNode()) {
            get(DeviceAdminService.class)
                    .changePortState(deviceId, portNumber, node.asBoolean());
            return Response.ok().build();
        }

        throw new IllegalArgumentException(INVALID_JSON);
    } catch (IOException ioe) {
        throw new IllegalArgumentException(ioe);
    }
}
 
Example #26
Source File: CienaFlowRuleProgrammable.java    From onos with Apache License 2.0 5 votes vote down vote up
private boolean removeCrossConnect(CrossConnectFlowRule xc) {
    //for now setting channel to 0 for remove rule
    if (xc == null) {
        return false;
    }
    // only handling lineside rule
    if (xc.isAddRule()) {
        PortNumber outPort = xc.addDrop();
        OchSignal signal = OchSignal.newDwdmSlot(xc.ochSignal().channelSpacing(), 0);
        return install(outPort, signal);
    }
    return false;
}
 
Example #27
Source File: CassiniTerminalDevicePowerConfig.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Getting target value of output power.
 * @param port port
 * @param component the component
 * @return target output power range
 */
@Override
public Optional<Range<Double>> getTargetPowerRange(PortNumber port, Object component) {
    double targetMin = -30;
    double targetMax = 1;
    return Optional.of(Range.open(targetMin, targetMax));
}
 
Example #28
Source File: GossipDeviceStore.java    From onos with Apache License 2.0 5 votes vote down vote up
private DeviceEvent removeDeviceInternal(DeviceId deviceId, Timestamp timestamp) {

        Map<ProviderId, DeviceDescriptions> descs = getOrCreateDeviceDescriptionsMap(deviceId);
        synchronized (descs) {
            // accept removal request if given timestamp is newer than
            // the latest Timestamp from Primary provider
            DeviceDescriptions primDescs = getPrimaryDescriptions(descs);
            if (primDescs == null) {
                return null;
            }

            Timestamp lastTimestamp = primDescs.getLatestTimestamp();

            // If no timestamp is set, default the timestamp to the last timestamp for the device.
            if (timestamp == null) {
                timestamp = lastTimestamp;
            }

            if (timestamp.compareTo(lastTimestamp) <= 0) {
                // outdated event ignore
                return null;
            }
            removalRequest.put(deviceId, timestamp);

            Device device = devices.remove(deviceId);
            // should DEVICE_REMOVED carry removed ports?
            Map<PortNumber, Port> ports = devicePorts.get(deviceId);
            if (ports != null) {
                ports.clear();
            }
            markOfflineInternal(deviceId, timestamp);
            descs.clear();
            // Forget about the device
            offline.remove(deviceId);
            return device == null ? null :
                    new DeviceEvent(DeviceEvent.Type.DEVICE_REMOVED, device, null);
        }
    }
 
Example #29
Source File: DeviceConfiguration.java    From onos with Apache License 2.0 5 votes vote down vote up
public PortNumber getPairLocalPort(DeviceId deviceId)
        throws DeviceConfigNotFoundException {
    SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId);
    if (srinfo != null) {
        return srinfo.pairLocalPort;
    } else {
        String message = "getPairLocalPort fails for device: " + deviceId + ".";
        throw new DeviceConfigNotFoundException(message);
    }
}
 
Example #30
Source File: LldpLinkProviderTest.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public Port getPort(DeviceId deviceId, PortNumber portNumber) {
    for (Port p : ports.get(deviceId)) {
        if (p.number().equals(portNumber)) {
            return p;
        }
    }
    return null;
}