Java Code Examples for org.onosproject.net.PortNumber#portNumber()

The following examples show how to use org.onosproject.net.PortNumber#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: DecodeInstructionCodecHelper.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Extracts port number of the given json node.
 *
 * @param jsonNode json node
 * @return port number
 */
private PortNumber getPortNumber(ObjectNode jsonNode) {
    PortNumber portNumber;
    JsonNode portNode = nullIsIllegal(jsonNode.get(InstructionCodec.PORT),
            InstructionCodec.PORT + InstructionCodec.ERROR_MESSAGE);
    if (portNode.isLong() || portNode.isInt()) {
        portNumber = PortNumber.portNumber(portNode.asLong());
    } else if (portNode.isTextual()) {
        portNumber = PortNumber.fromString(portNode.textValue());
    } else {
        throw new IllegalArgumentException("Port value "
                + portNode.toString()
                + " is not supported");
    }
    return portNumber;
}
 
Example 2
Source File: ControlPlaneRedirectManagerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Tests adding while updating the networkConfig.
 */
@Test
public void testUpdateNetworkConfig() {
    ConnectPoint sw1eth4 = new ConnectPoint(DEVICE_ID, PortNumber.portNumber(4));
    List<InterfaceIpAddress> interfaceIpAddresses = new ArrayList<>();
    interfaceIpAddresses.add(
            new InterfaceIpAddress(IpAddress.valueOf("192.168.40.101"), IpPrefix.valueOf("192.168.40.0/24"))
    );
    interfaceIpAddresses.add(
            new InterfaceIpAddress(IpAddress.valueOf("2000::ff"), IpPrefix.valueOf("2000::ff/120"))
    );

    Interface sw1Eth4 = new Interface(sw1eth4.deviceId().toString(), sw1eth4, interfaceIpAddresses,
            MacAddress.valueOf("00:00:00:00:00:04"), VlanId.NONE);
    interfaces.add(sw1Eth4);
    EasyMock.reset(flowObjectiveService);
    setUpFlowObjectiveService();
    networkConfigListener
            .event(new NetworkConfigEvent(Type.CONFIG_UPDATED, dev3, RoutingService.ROUTER_CONFIG_CLASS));
    networkConfigService.addListener(networkConfigListener);
    verify(flowObjectiveService);
}
 
Example 3
Source File: PacketLinkRealizedByOpticalTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Checks the construction of OpticalConnectivityId object with OpticalCircuitIntent.
 */
@Test
public void testCreateWithCircuitIntent() {
    ConnectPoint cp1 = new ConnectPoint(DeviceId.deviceId("of:0000000000000001"), PortNumber.portNumber(1L));
    ConnectPoint cp2 = new ConnectPoint(DeviceId.deviceId("of:0000000000000002"), PortNumber.portNumber(2L));
    OpticalCircuitIntent circuitIntent = OpticalCircuitIntent.builder()
            .appId(appId)
            .src(cp1)
            .dst(cp2)
            .bidirectional(true)
            .key(Key.of(0, appId))
            .signalType(CltSignalType.CLT_1GBE)
            .build();

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

    assertNotNull(plink);
    assertEquals(plink.src(), cp1);
    assertEquals(plink.dst(), cp2);
    assertEquals((long) plink.bandwidth().bps(), CltSignalType.CLT_1GBE.bitRate());
}
 
Example 4
Source File: OspfTopologyProvider.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Builds link description.
 *
 * @param ospfRouter  OSPF router instance
 * @param ospfLinkTed OSPF link TED instance
 * @return link description instance
 */
private LinkDescription buildLinkDes(OspfRouter ospfRouter, OspfLinkTed ospfLinkTed) {
    long srcAddress = 0;
    long dstAddress = 0;
    boolean localPseduo = false;
    //Changing of port numbers
    srcAddress = Ip4Address.valueOf(ospfRouter.routerIp().toString()).toInt();
    dstAddress = Ip4Address.valueOf(ospfRouter.neighborRouterId().toString()).toInt();
    DeviceId srcId = DeviceId.deviceId(OspfRouterId.uri(ospfRouter.routerIp()));
    DeviceId dstId = DeviceId.deviceId(OspfRouterId.uri(ospfRouter.neighborRouterId()));
    if (ospfRouter.isDr()) {
        localPseduo = true;
    }
    if (localPseduo && srcAddress == 0) {
        srcAddress = PSEUDO_PORT;
    }

    ConnectPoint src = new ConnectPoint(srcId, PortNumber.portNumber(srcAddress));
    ConnectPoint dst = new ConnectPoint(dstId, PortNumber.portNumber(dstAddress));

    return new DefaultLinkDescription(src, dst, Link.Type.DIRECT, false);
}
 
Example 5
Source File: NullPacketProvider.java    From onos with Apache License 2.0 5 votes vote down vote up
private void sendEvent(Device device) {
    // Make it look like things came from ports attached to hosts
    eth.setSourceMACAddress("00:00:00:10:00:0" + SRC_HOST)
            .setDestinationMACAddress("00:00:00:10:00:0" + DST_HOST);
    InboundPacket inPkt = new DefaultInboundPacket(
            new ConnectPoint(device.id(), PortNumber.portNumber(SRC_HOST)),
            eth, ByteBuffer.wrap(eth.serialize()));
    providerService.processPacket(new NullPacketContext(inPkt, null));
}
 
Example 6
Source File: OplinkSwitchProtection.java    From onos with Apache License 2.0 5 votes vote down vote up
private DeviceId getPeerId() {
    ConnectPoint dstCp = new ConnectPoint(data().deviceId(), PortNumber.portNumber(VIRTUAL_PORT));
    Set<Link> links = handler().get(LinkService.class).getIngressLinks(dstCp);

    for (Link l : links) {
        if (l.type() == Link.Type.VIRTUAL) {
            // this device is the destination and peer is the source.
            return l.src().deviceId();
        }
    }

    return data().deviceId();
}
 
Example 7
Source File: BasicInterpreterImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public InboundPacket mapInboundPacket(PiPacketOperation packetIn, DeviceId deviceId)
        throws PiInterpreterException {
    // Assuming that the packet is ethernet, which is fine since basic.p4
    // can deparse only ethernet packets.
    Ethernet ethPkt;
    try {
        ethPkt = Ethernet.deserializer().deserialize(packetIn.data().asArray(), 0,
                                                     packetIn.data().size());
    } catch (DeserializationException dex) {
        throw new PiInterpreterException(dex.getMessage());
    }

    // Returns the ingress port packet metadata.
    Optional<PiPacketMetadata> packetMetadata = packetIn.metadatas()
            .stream().filter(m -> m.id().equals(INGRESS_PORT))
            .findFirst();

    if (packetMetadata.isPresent()) {
        ImmutableByteSequence portByteSequence = packetMetadata.get().value();
        short s = portByteSequence.asReadOnlyBuffer().getShort();
        ConnectPoint receivedFrom = new ConnectPoint(deviceId, PortNumber.portNumber(s));
        ByteBuffer rawData = ByteBuffer.wrap(packetIn.data().asArray());
        return new DefaultInboundPacket(receivedFrom, ethPkt, rawData);
    } else {
        throw new PiInterpreterException(format(
                "Missing metadata '%s' in packet-in received from '%s': %s",
                INGRESS_PORT, deviceId, packetIn));
    }
}
 
Example 8
Source File: OvsdbHostProvider.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void handle(OvsdbEvent<EventSubject> event) {
    OvsdbEventSubject subject = null;
    if (event.subject() instanceof OvsdbEventSubject) {
        subject = (OvsdbEventSubject) event.subject();
    }
    checkNotNull(subject, "EventSubject is not null");
    // If ifaceid is null,it indicates this is not a vm port.
    if (subject.ifaceid() == null) {
        return;
    }
    switch (event.type()) {
    case PORT_ADDED:
        HostId hostId = HostId.hostId(subject.hwAddress(), VlanId.vlanId());
        DeviceId deviceId = DeviceId.deviceId(uri(subject.dpid().value()));
        PortNumber portNumber = PortNumber.portNumber(subject
                .portNumber().value(), subject.portName().value());
        HostLocation loaction = new HostLocation(deviceId, portNumber,
                                                 0L);
        SparseAnnotations annotations = DefaultAnnotations.builder()
                .set("ifaceid", subject.ifaceid().value()).build();
        HostDescription hostDescription = new DefaultHostDescription(
                                                                     subject.hwAddress(),
                                                                     VlanId.vlanId(),
                                                                     loaction,
                                                                     annotations);
        providerService.hostDetected(hostId, hostDescription, false);
        break;
    case PORT_REMOVED:
        HostId host = HostId.hostId(subject.hwAddress(), VlanId.vlanId());
        providerService.hostVanished(host);
        break;
    default:
        break;
    }

}
 
Example 9
Source File: OplinkSwitchProtection.java    From onos with Apache License 2.0 5 votes vote down vote up
private void removeLinkToPeer(DeviceId peerId) {
    if (peerId == null) {
        log.warn("PeerID is null for device {}", data().deviceId());
        return;
    }
    ConnectPoint dstCp = new ConnectPoint(data().deviceId(), PortNumber.portNumber(VIRTUAL_PORT));
    ConnectPoint srcCp = new ConnectPoint(peerId, PortNumber.portNumber(VIRTUAL_PORT));
    LinkKey link = linkKey(srcCp, dstCp);
    handler().get(NetworkConfigService.class).removeConfig(link, BasicLinkConfig.class);
}
 
Example 10
Source File: OmsPortHelperTest.java    From onos with Apache License 2.0 5 votes vote down vote up
@Test
public void testOmsPortDescriptionCanBeConvertedToOmsPort() {
    PortNumber pn = PortNumber.portNumber(4900);

    boolean isEnabled = true;
    String anKey = "Base";
    String anValue = "value";
    SparseAnnotations an = DefaultAnnotations.builder()
            .set(anKey, anValue)
            .build();

    Frequency minF = Frequency.ofGHz(3);
    Frequency maxF = Frequency.ofGHz(33);
    Frequency grid = Frequency.ofGHz(2);

    PortDescription portDescription = OmsPortHelper.omsPortDescription(pn, isEnabled, minF, maxF, grid, an);
    Port port = new DefaultPort(DEV,
                                portDescription.portNumber(),
                                portDescription.isEnabled(),
                                portDescription.type(),
                                portDescription.portSpeed(),
                                portDescription.annotations());

    Optional<OmsPort> maybeOms = OmsPortHelper.asOmsPort(port);
    assertTrue(maybeOms.isPresent());

    OmsPort oms = maybeOms.get();

    assertThat(oms.isEnabled(), is(isEnabled));
    assertThat(oms.number(), is(pn));
    assertThat(oms.annotations().value(anKey), is(anValue));

    assertThat("type is always OMS", oms.type(), is(Port.Type.OMS));
    assertThat("port speed is undefined", oms.portSpeed(), is(equalTo(0L)));

    assertThat(oms.maxFrequency(), is(maxF));
    assertThat(oms.minFrequency(), is(minF));
    assertThat(oms.grid(), is(grid));
    assertThat("((33-3)/2)+1 = 16", oms.totalChannels(), is((short) 16));
}
 
Example 11
Source File: OFAgentVirtualGroupBucketEntryBuilder.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Builds a GroupBuckets.
 *
 * @return GroupBuckets object, a list of GroupBuckets
 */
public GroupBuckets build() {
    List<GroupBucket> bucketList = Lists.newArrayList();

    for (OFBucket bucket: ofBuckets) {
        TrafficTreatment treatment = buildTreatment(bucket.getActions());
        // TODO: Use GroupBucketEntry
        GroupBucket groupBucket = null;
        switch (type) {
            case INDIRECT:
                groupBucket =
                        DefaultGroupBucket.createIndirectGroupBucket(treatment);
                break;
            case SELECT:
                groupBucket =
                        DefaultGroupBucket.createSelectGroupBucket(treatment, (short) bucket.getWeight());
                break;
            case FF:
                PortNumber port =
                        PortNumber.portNumber(bucket.getWatchPort().getPortNumber());
                GroupId groupId =
                        new GroupId(bucket.getWatchGroup().getGroupNumber());
                groupBucket =
                        DefaultGroupBucket.createFailoverGroupBucket(treatment,
                                port, groupId);
                break;
            case ALL:
                groupBucket =
                        DefaultGroupBucket.createAllGroupBucket(treatment);
                break;
            default:
                log.error("Unsupported Group type : {}", type);
        }
        if (groupBucket != null) {
            bucketList.add(groupBucket);
        }
    }
    return new GroupBuckets(bucketList);
}
 
Example 12
Source File: DefaultVirtualLinkTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the DefaultVirtualLink Builder to ensure that the dst cannot be null.
 */
@Test(expected = NullPointerException.class)
public void testBuilderNullDst() {
    DefaultVirtualDevice device1 =
            new DefaultVirtualDevice(NetworkId.networkId(0), DID1);
    DefaultVirtualDevice device2 =
            new DefaultVirtualDevice(NetworkId.networkId(0), DID2);
    ConnectPoint src = new ConnectPoint(device1.id(), PortNumber.portNumber(1));
    ConnectPoint dst = new ConnectPoint(device2.id(), PortNumber.portNumber(2));

    DefaultVirtualLink.builder()
            .dst(null)
            .build();
}
 
Example 13
Source File: VirtualLinkCreateCommand.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
protected void doExecute() {
    VirtualNetworkAdminService service = get(VirtualNetworkAdminService.class);
    ConnectPoint src = new ConnectPoint(DeviceId.deviceId(srcDeviceId), PortNumber.portNumber(srcPortNum));
    ConnectPoint dst = new ConnectPoint(DeviceId.deviceId(dstDeviceId), PortNumber.portNumber(dstPortNum));

    service.createVirtualLink(NetworkId.networkId(networkId), src, dst);
    if (bidirectional) {
        service.createVirtualLink(NetworkId.networkId(networkId), dst, src);
    }
    print("Virtual link successfully created.");
}
 
Example 14
Source File: TapiDeviceDescriptionDiscovery.java    From onos with Apache License 2.0 5 votes vote down vote up
protected List<PortDescription> parseTapiPorts(JsonNode tapiContext) {
    List<PortDescription> ports = Lists.newArrayList();
    /*
     This annotations are used to store persistent mapping information between TAPI SIP's uuid
     and ONOS device portNumbers. This is needed to be publicly available at least within ODTN app
     when connectivity services will be sent to OLS Controller.
     */
    DefaultAnnotations.Builder annotations = DefaultAnnotations.builder();
    Iterator<JsonNode> iter = tapiContext.get(CONTEXT).get(SERVICE_INTERFACE_POINT).iterator();
    while (iter.hasNext()) {
        JsonNode sipAttributes = iter.next();
        if (checkValidEndpoint(sipAttributes)) {
            String uuid = sipAttributes.get(UUID).textValue();
            String[] uuidSeg = uuid.split("-");
            PortNumber portNumber = PortNumber.portNumber(uuidSeg[uuidSeg.length - 1]);
            annotations.set(UUID, uuid);

            JsonNode mcPool = sipAttributes.get(MEDIA_CHANNEL_SERVICE_INTERFACE_POINT_SPEC).get(MC_POOL);
            // We get the first OCH signal as reported by the device.
            OchSignal ochSignal = getOchSignal(mcPool).iterator().next();
            //add och port
            ports.add(ochPortDescription(portNumber, true, OduSignalType.ODU4,
                    false, ochSignal, annotations.build()));


        } else {
            log.error("SIP {} is not valid", sipAttributes);
        }
    }
    log.debug("PortList: {}", ports);
    return ImmutableList.copyOf(ports);
}
 
Example 15
Source File: PortNumberCodec.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public PortNumber decode(int value) {
    return PortNumber.portNumber(value);
}
 
Example 16
Source File: MepCodec.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Decodes the Mep entity from JSON.
 *
 * @param json    JSON to decode
 * @param context decoding context
 * @param mdName The MD name
 * @param maName The MA name
 * @return decoded Mep
 * @throws java.lang.UnsupportedOperationException if the codec does not
 *                                                 support decode operations
 */
 public Mep decode(ObjectNode json, CodecContext context, String
                    mdName, String maName) {
    if (json == null || !json.isObject()) {
        return null;
    }

    JsonNode mepNode = json.get("mep");

    int mepId = Integer.parseInt(
            nullIsIllegal(mepNode.get("mepId"), "mepId is required").asText());
    DeviceId deviceId = DeviceId.deviceId(
            nullIsIllegal(mepNode.get("deviceId"), "deviceId is required")
            .asText());
    PortNumber port = PortNumber
            .portNumber(Long.parseLong(
                    nullIsIllegal(mepNode.get("port"), "port is required")
                    .asText()));
    MepDirection direction = MepDirection.valueOf(
            nullIsIllegal(mepNode.get("direction"), "direction is required").
            asText());

    try {
        MdId mdId = MdIdCharStr.asMdId(mdName);
        MaIdShort maId = MaIdCharStr.asMaId(maName);
        MepBuilder mepBuilder = DefaultMep
                .builder(MepId.valueOf((short) mepId),
                        deviceId, port, direction, mdId, maId);

        if (mepNode.get(PRIMARY_VID) != null) {
            mepBuilder.primaryVid(VlanId.vlanId(
                    (short) mepNode.get(PRIMARY_VID).asInt(0)));
        }

        if (mepNode.get(ADMINISTRATIVE_STATE) != null) {
            mepBuilder.administrativeState(mepNode.get(ADMINISTRATIVE_STATE)
                    .asBoolean());
        }

        if (mepNode.get(CCM_LTM_PRIORITY) != null) {
            mepBuilder.ccmLtmPriority(
                    Priority.values()[mepNode.get(CCM_LTM_PRIORITY).asInt(0)]);
        }

        if (mepNode.get(CCI_ENABLED) != null) {
            mepBuilder.cciEnabled(mepNode.get(CCI_ENABLED).asBoolean());
        }

        if (mepNode.get(LOWEST_FAULT_PRIORITY_DEFECT) != null) {
            mepBuilder.lowestFaultPriorityDefect(
                    Mep.LowestFaultDefect.values()[mepNode.get(LOWEST_FAULT_PRIORITY_DEFECT).asInt()]);
        }

        if (mepNode.get(DEFECT_ABSENT_TIME) != null) {
            mepBuilder.defectAbsentTime(
                    Duration.parse(mepNode.get(DEFECT_ABSENT_TIME).asText()));
        }

        if (mepNode.get(DEFECT_PRESENT_TIME) != null) {
            mepBuilder.defectPresentTime(
                    Duration.parse(mepNode.get(DEFECT_PRESENT_TIME).asText()));
        }

        if (mepNode.get(FNG_ADDRESS) != null) {
            mepBuilder.fngAddress((new FngAddressCodec())
                    .decode((ObjectNode) mepNode, context));
        }


        return mepBuilder.build();
    } catch (CfmConfigException e) {
        throw new IllegalArgumentException(e);
    }
}
 
Example 17
Source File: OpenRoadmDeviceDescription.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Parses port information.
 *
 *  @param list  List of port descriptions to append to.
 *  @param nodeId OpenROADM node identifier.
 *  @param circuitPackName Name of the circuit pack the ports belong to
 *  @param ports hierarchical conf containing all the ports for the circuit
 * pack
 *  @param circuitPacks all the circuit packs (to correlate data).
 *  @param extLinks Hierarchical configuration containing all the ext.
 * links.
 */
protected void parsePorts(List<PortDescription> list, String nodeId,
                          String circuitPackName,
                          List<HierarchicalConfiguration> ports,
                          List<HierarchicalConfiguration> circuitPacks,
                          List<HierarchicalConfiguration> extLinks) {
    checkNotNull(nodeId);
    checkNotNull(circuitPackName);
    for (HierarchicalConfiguration port : ports) {
        try {
            String portName = checkNotNull(port.getString("port-name"));
            long portNum = Long.parseLong(port.getString("label"));
            PortNumber pNum = PortNumber.portNumber(portNum);
            PortNumber reversepNum = findReversePort(port, circuitPacks);
            // To see if we have an external port
            HierarchicalConfiguration eLink = null;
            for (HierarchicalConfiguration extLink : extLinks) {
                String eln =
                    checkNotNull(extLink.getString("external-link-name"));
                String esnid =
                    checkNotNull(extLink.getString("source/node-id"));
                String escpn =
                    checkNotNull(extLink.getString("source/circuit-pack-name"));
                String espn =
                    checkNotNull(extLink.getString("source/port-name"));
                if (nodeId.equals(esnid) && circuitPackName.equals(escpn) &&
                        portName.equals(espn)) {
                    eLink = extLink;
                }
            }
            PortDescription pd = parsePortComponent(
                    nodeId, circuitPackName, pNum, reversepNum, port, eLink);
            if (pd != null) {
                list.add(pd);
            }
        } catch (NetconfException e) {
            log.error("[OPENROADM] {} NetConf exception", did());
            return;
        }
    }
}
 
Example 18
Source File: ModulationWebResource.java    From onos with Apache License 2.0 4 votes vote down vote up
public void decode(ObjectNode json) {
    if (json == null || !json.isObject()) {
        throw new IllegalArgumentException(JSON_INVALID);
    }

    JsonNode devicesNode = json.get(DEVICES);
    if (!devicesNode.isObject()) {
        throw new IllegalArgumentException(JSON_INVALID);
    }

    Iterator<Map.Entry<String, JsonNode>> deviceEntries = devicesNode.fields();
    while (deviceEntries.hasNext()) {
        Map.Entry<String, JsonNode> deviceEntryNext = deviceEntries.next();
        String deviceId = deviceEntryNext.getKey();
        ModulationConfig<Object> modulationConfig = getModulationConfig(deviceId);
        JsonNode portsNode = deviceEntryNext.getValue();
        if (!portsNode.isObject()) {
            throw new IllegalArgumentException(JSON_INVALID);
        }

        Iterator<Map.Entry<String, JsonNode>> portEntries = portsNode.fields();
        while (portEntries.hasNext()) {
            Map.Entry<String, JsonNode> portEntryNext = portEntries.next();
            PortNumber portNumber = PortNumber.portNumber(portEntryNext.getKey());
            JsonNode componentsNode = portEntryNext.getValue();
            Iterator<Map.Entry<String, JsonNode>> componentEntries = componentsNode.fields();
            while (componentEntries.hasNext()) {
                Direction direction = null;
                Map.Entry<String, JsonNode> componentEntryNext = componentEntries.next();
                try {
                    direction = Direction.valueOf(componentEntryNext.getKey().toUpperCase());
                } catch (IllegalArgumentException e) {
                    // TODO: Handle other components
                }

                JsonNode bitRateNode = componentEntryNext.getValue();
                if (!bitRateNode.isObject()) {
                    throw new IllegalArgumentException(JSON_INVALID);
                }
                Long targetBitRate = bitRateNode.get(TARGET_BITRATE).asLong();
                if (direction != null) {
                    modulationConfig.setModulationScheme(portNumber, direction, targetBitRate);
                }
            }
        }
    }
}
 
Example 19
Source File: PcepReleaseTunnelProviderTest.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Tests releasing SR based tunnel.
 */
@Test
public void testCasePcepReleaseSrTunnel() {
    Tunnel tunnel;
    Path path;
    List<Link> links = new ArrayList<>();

    ProviderId pid = new ProviderId("pcep", PROVIDER_ID);

    IpAddress srcIp = IpAddress.valueOf(0xB6024E20);
    IpElementId srcElementId = IpElementId.ipElement(srcIp);

    IpAddress dstIp = IpAddress.valueOf(0xB6024E21);
    IpElementId dstElementId = IpElementId.ipElement(dstIp);

    IpTunnelEndPoint ipTunnelEndPointSrc;
    ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp);

    IpTunnelEndPoint ipTunnelEndPointDst;
    ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp);

    ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));

    ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023));

    Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
            .type(Link.Type.DIRECT).build();
    links.add(link);

    path = new DefaultPath(pid, links, ScalarWeight.toWeight(20), EMPTY);

    Annotations annotations = DefaultAnnotations.builder()
            .set(LSP_SIG_TYPE, SR_WITHOUT_SIGNALLING.name())
            .build();

    tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
                               new GroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
                               path, annotations);

    // for releasing tunnel tunnel should exist in db
    PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.DELETE);
    pcepTunnelData.setPlspId(1);
    StatefulIPv4LspIdentifiersTlv tlv = new StatefulIPv4LspIdentifiersTlv(0, (short) 1, (short) 2, 3, 4);
    pcepTunnelData.setStatefulIpv4IndentifierTlv(tlv);
    tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);

    tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData);
    controller.getClient(PccId.pccId(IpAddress.valueOf(0xB6024E20))).setCapability(
            new ClientCapability(true, true, true, true, true));

    tunnelProvider.releaseTunnel(tunnel);
    assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
}
 
Example 20
Source File: TopologySimulator.java    From onos with Apache License 2.0 2 votes vote down vote up
/**
 * Creates simulated link between two devices.
 *
 * @param i  index of one simulated device
 * @param j  index of another simulated device
 * @param pi port number of i-th device
 * @param pj port number of j-th device
 */
public void createLink(int i, int j, int pi, int pj) {
    ConnectPoint one = new ConnectPoint(deviceIds.get(i), PortNumber.portNumber(pi));
    ConnectPoint two = new ConnectPoint(deviceIds.get(j), PortNumber.portNumber(pj));
    createLink(one, two);
}