Search in sources :

Example 16 with RouteDistinguisher

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.RouteDistinguisher in project bgpcep by opendaylight.

the class RouteDistinguisherUtil method serializeRouteDistinquisher.

/**
 * Serializes route distinguisher according to type and writes into ByteBuf.
 */
public static void serializeRouteDistinquisher(final RouteDistinguisher distinguisher, final ByteBuf byteAggregator) {
    requireNonNull(distinguisher);
    Preconditions.checkState(byteAggregator != null && byteAggregator.isWritable(RD_LENGTH), "Cannot write Route Distinguisher to provided buffer.");
    if (distinguisher.getRdTwoOctetAs() != null) {
        final String[] values = distinguisher.getRdTwoOctetAs().getValue().split(SEPARATOR);
        byteAggregator.writeShort(RDType.AS_2BYTE.value);
        ByteBufWriteUtil.writeUnsignedShort(Integer.parseInt(values[1]), byteAggregator);
        final long assignedNumber = Integer.parseUnsignedInt(values[2]);
        ByteBufWriteUtil.writeUnsignedInt(assignedNumber, byteAggregator);
    } else if (distinguisher.getRdAs() != null) {
        final String[] values = distinguisher.getRdAs().getValue().split(SEPARATOR);
        byteAggregator.writeShort(RDType.AS_4BYTE.value);
        final long admin = Integer.parseUnsignedInt(values[0]);
        ByteBufWriteUtil.writeUnsignedInt(admin, byteAggregator);
        ByteBufWriteUtil.writeUnsignedShort(Integer.parseInt(values[1]), byteAggregator);
    } else if (distinguisher.getRdIpv4() != null) {
        final String[] values = distinguisher.getRdIpv4().getValue().split(SEPARATOR);
        final Ipv4Address ip = new Ipv4Address(values[0]);
        byteAggregator.writeShort(RDType.IPV4.value);
        ByteBufWriteUtil.writeIpv4Address(ip, byteAggregator);
        ByteBufWriteUtil.writeUnsignedShort(Integer.parseInt(values[1]), byteAggregator);
    } else {
        LOG.warn("Unable to serialize Route Distinguisher. Invalid RD value found. RD={}", distinguisher);
    }
}
Also used : Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)

Example 17 with RouteDistinguisher

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.RouteDistinguisher in project bgpcep by opendaylight.

the class AbstractFlowspecL3vpnNlriParser method stringNlri.

@Override
public String stringNlri(final DataContainerNode<?> flowspec) {
    final StringBuilder buffer = new StringBuilder();
    final RouteDistinguisher rd = extractRouteDistinguisher(flowspec, RD_NID);
    if (rd != null) {
        buffer.append("[l3vpn with route-distinguisher ").append(rd.getValue()).append("] ");
    }
    buffer.append(super.stringNlri(flowspec));
    return buffer.toString();
}
Also used : RouteDistinguisherUtil.extractRouteDistinguisher(org.opendaylight.bgp.concepts.RouteDistinguisherUtil.extractRouteDistinguisher) RouteDistinguisher(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.RouteDistinguisher)

Example 18 with RouteDistinguisher

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.RouteDistinguisher in project netvirt by opendaylight.

the class BgpUtil method getVrfFromRd.

/**
 * get the vrf with the RouterDistinguisher pass in param.
 * @param rd is the RouteDistinguisher of vrf
 * @return the vrf of rd or null if no exist
 */
public Vrfs getVrfFromRd(String rd) {
    Vrfs vrfs = null;
    KeyedInstanceIdentifier<Vrfs, VrfsKey> id = InstanceIdentifier.create(Bgp.class).child(VrfsContainer.class).child(Vrfs.class, new VrfsKey(rd));
    Optional<Vrfs> vrfsFromDs = Optional.empty();
    try {
        vrfsFromDs = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
    } catch (ExecutionException | InterruptedException e) {
        LOG.error("Exception while reading BGP VRF table for the Vpn Rd {}", rd, e);
    }
    if (vrfsFromDs.isPresent()) {
        vrfs = vrfsFromDs.get();
    }
    return vrfs;
}
Also used : Vrfs(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.vrfscontainer.Vrfs) VrfsKey(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.vrfscontainer.VrfsKey) VrfsContainer(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.VrfsContainer) ExecutionException(java.util.concurrent.ExecutionException)

Example 19 with RouteDistinguisher

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.RouteDistinguisher in project bgpcep by opendaylight.

the class RouteDistinguisherUtil method parseRouteDistinguisher.

/**
 * Parses three types of route distinguisher from given ByteBuf.
 */
public static RouteDistinguisher parseRouteDistinguisher(final ByteBuf buffer) {
    Preconditions.checkState(buffer != null && buffer.isReadable(RD_LENGTH), "Cannot read Route Distinguisher from provided buffer.");
    final int type = buffer.readUnsignedShort();
    final RDType rdType = RDType.valueOf(type);
    switch(rdType) {
        case AS_2BYTE:
            return new RouteDistinguisher(new RdTwoOctetAs(new StringBuilder().append(type).append(SEPARATOR).append(buffer.readUnsignedShort()).append(SEPARATOR).append(buffer.readUnsignedInt()).toString()));
        case IPV4:
            return new RouteDistinguisher(new RdIpv4(new StringBuilder().append(Ipv4Util.addressForByteBuf(buffer).getValue()).append(SEPARATOR).append(buffer.readUnsignedShort()).toString()));
        case AS_4BYTE:
            return new RouteDistinguisher(new RdAs(new StringBuilder().append(buffer.readUnsignedInt()).append(SEPARATOR).append(buffer.readUnsignedShort()).toString()));
        default:
            // now that this RD type is not supported, we want to read the remain 6 bytes
            // in order to get the byte index correct
            final StringBuilder routeDistiguisher = new StringBuilder();
            for (int i = 0; i < 6; i++) {
                routeDistiguisher.append("0x").append(Integer.toHexString(buffer.readByte() & 0xFF)).append(' ');
            }
            LOG.debug("Invalid Route Distinguisher: type={}, rawRouteDistinguisherValue={}", type, routeDistiguisher);
            throw new IllegalArgumentException("Invalid Route Distinguisher type " + type);
    }
}
Also used : RdTwoOctetAs(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.RdTwoOctetAs) RdAs(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.RdAs) RdIpv4(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.RdIpv4) RouteDistinguisher(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.RouteDistinguisher)

Example 20 with RouteDistinguisher

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.RouteDistinguisher in project bgpcep by opendaylight.

the class RouteDistinguisherUtilTest method testIpv4RouteDistinguisher.

@Test
public void testIpv4RouteDistinguisher() {
    final RouteDistinguisher expected = createRouteDistinguisher(1, IP_ADDRESS, IP_PORT);
    final RouteDistinguisher parsed = RouteDistinguisherUtil.parseRouteDistinguisher(Unpooled.copiedBuffer(IP_BYTES));
    assertEquals(expected.getRdIpv4(), parsed.getRdIpv4());
    final ByteBuf byteAggregator = Unpooled.buffer(IP_BYTES.length);
    RouteDistinguisherUtil.serializeRouteDistinquisher(expected, byteAggregator);
    assertArrayEquals(IP_BYTES, byteAggregator.array());
    assertEquals(IP_ADDRESS + SEPARATOR + IP_PORT, parsed.getRdIpv4().getValue());
}
Also used : RouteDistinguisher(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.RouteDistinguisher) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Aggregations

RouteDistinguisher (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.RouteDistinguisher)25 Test (org.junit.Test)15 ByteBuf (io.netty.buffer.ByteBuf)13 Flowspec (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.Flowspec)13 ArrayList (java.util.ArrayList)9 RouteDistinguisherUtil.extractRouteDistinguisher (org.opendaylight.bgp.concepts.RouteDistinguisherUtil.extractRouteDistinguisher)9 FlowspecBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.FlowspecBuilder)8 AttributesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder)8 FlowspecType (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.FlowspecType)6 DestinationFlowspecL3vpnIpv4Builder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.l3vpn.destination.ipv4.DestinationFlowspecL3vpnIpv4Builder)6 DestinationFlowspecL3vpnIpv6Builder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.l3vpn.destination.ipv6.DestinationFlowspecL3vpnIpv6Builder)6 List (java.util.List)5 Collections (java.util.Collections)4 Mockito.doReturn (org.mockito.Mockito.doReturn)4 FlowspecL3vpnIpv4NlriParser (org.opendaylight.protocol.bgp.flowspec.l3vpn.ipv4.FlowspecL3vpnIpv4NlriParser)4 DestinationFlowspecL3vpnIpv4 (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.l3vpn.destination.ipv4.DestinationFlowspecL3vpnIpv4)3 DestinationFlowspecL3vpnIpv6 (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.l3vpn.destination.ipv6.DestinationFlowspecL3vpnIpv6)3 AttributesReachBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.AttributesReachBuilder)3 AttributesUnreachBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.AttributesUnreachBuilder)3 MpReachNlriBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.reach.MpReachNlriBuilder)3