use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.BgpTableType in project bgpcep by opendaylight.
the class TableTypeActivatorTest method testActivator.
@Test
public void testActivator() {
final TableTypeActivator tableTypeActivator = new TableTypeActivator();
final SimpleBGPTableTypeRegistryProvider registry = new SimpleBGPTableTypeRegistryProvider();
tableTypeActivator.startBGPTableTypeRegistryProvider(registry);
final Optional<Class<? extends AfiSafiType>> afiSafiType = registry.getAfiSafiType(IPV4);
Assert.assertEquals(L3VPNIPV4UNICAST.class, afiSafiType.get());
final Optional<Class<? extends AfiSafiType>> afiSafiType2 = registry.getAfiSafiType(IPV6);
Assert.assertEquals(L3VPNIPV6UNICAST.class, afiSafiType2.get());
final Optional<BgpTableType> tableType = registry.getTableType(L3VPNIPV4UNICAST.class);
Assert.assertEquals(IPV4, tableType.get());
final Optional<BgpTableType> tableType2 = registry.getTableType(L3VPNIPV6UNICAST.class);
Assert.assertEquals(IPV6, tableType2.get());
tableTypeActivator.stopBGPTableTypeRegistryProvider();
tableTypeActivator.close();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.BgpTableType in project bgpcep by opendaylight.
the class BGPRouteRefreshMessageParser method parseMessageBody.
/**
* Parses BGP Route Refresh message to bytes.
*
* @param body ByteBuf to be parsed
* @param messageLength the length of the message
* @return {@link RouteRefresh} which represents BGP notification message
* @throws BGPDocumentedException if parsing goes wrong
*/
@Override
public RouteRefresh parseMessageBody(final ByteBuf body, final int messageLength) throws BGPDocumentedException {
Preconditions.checkArgument(body != null, "Body buffer cannot be null.");
if (body.readableBytes() < TRIPLET_BYTE_SIZE) {
throw BGPDocumentedException.badMessageLength("RouteRefresh message is too small.", messageLength);
}
final Optional<BgpTableType> parsedAfiSafi = MultiprotocolCapabilitiesUtil.parseMPAfiSafi(body, this.afiReg, this.safiReg);
if (!parsedAfiSafi.isPresent()) {
throw new BGPDocumentedException("Unsupported afi/safi in Route Refresh message.", BGPError.WELL_KNOWN_ATTR_NOT_RECOGNIZED);
}
return new RouteRefreshBuilder(parsedAfiSafi.get()).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.BgpTableType in project bgpcep by opendaylight.
the class MultiPathSupportImplTest method testIsTableTypeSupported.
@Test
public void testIsTableTypeSupported() {
final List<AddressFamilies> supportedTables = new ArrayList<>();
final BgpTableType ipv4Unicast = new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
final BgpTableType ipv4L3vpn = new BgpTableTypeImpl(Ipv4AddressFamily.class, MplsLabeledVpnSubsequentAddressFamily.class);
final BgpTableType ipv6Unicast = new BgpTableTypeImpl(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class);
final BgpTableType ipv6L3vpn = new BgpTableTypeImpl(Ipv6AddressFamily.class, MplsLabeledVpnSubsequentAddressFamily.class);
supportedTables.add(createAddPathCapability(ipv4Unicast, SendReceive.Send));
supportedTables.add(createAddPathCapability(ipv4L3vpn, SendReceive.Receive));
supportedTables.add(createAddPathCapability(ipv6Unicast, SendReceive.Both));
final MultiPathSupport multiPathSupport = MultiPathSupportImpl.createParserMultiPathSupport(supportedTables);
Assert.assertTrue(multiPathSupport.isTableTypeSupported(ipv4Unicast));
Assert.assertTrue(multiPathSupport.isTableTypeSupported(ipv6Unicast));
Assert.assertFalse(multiPathSupport.isTableTypeSupported(ipv4L3vpn));
Assert.assertFalse(multiPathSupport.isTableTypeSupported(ipv6L3vpn));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.BgpTableType in project bgpcep by opendaylight.
the class SimpleNlriRegistry method parseMpReach.
@Override
public MpReachNlri parseMpReach(final ByteBuf buffer, final PeerSpecificParserConstraint constraint) throws BGPParsingException {
final MpReachNlriBuilder builder = new MpReachNlriBuilder();
final Class<? extends AddressFamily> afi = getAfi(buffer);
final Class<? extends SubsequentAddressFamily> safi = getSafi(buffer);
builder.setAfi(afi);
builder.setSafi(safi);
final BgpTableType key = createKey(builder.getAfi(), builder.getSafi());
final int nextHopLength = buffer.readUnsignedByte();
if (nextHopLength != 0) {
final NextHopParserSerializer nextHopParser = this.nextHopParsers.get(key);
if (nextHopParser != null) {
builder.setCNextHop(nextHopParser.parseNextHop(buffer.readSlice(nextHopLength)));
} else {
builder.setCNextHop(NextHopUtil.parseNextHop(buffer.readSlice(nextHopLength)));
LOG.warn("NexHop Parser/Serializer for AFI/SAFI ({},{}) not bound", afi, safi);
}
}
buffer.skipBytes(RESERVED);
final ByteBuf nlri = buffer.slice();
final NlriParser parser = this.handlers.get(key);
if (parser == null) {
LOG.warn(PARSER_NOT_FOUND, key);
} else {
parser.parseNlri(nlri, builder, constraint);
}
return builder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.BgpTableType in project bgpcep by opendaylight.
the class SimpleNlriRegistry method registerNlriParser.
synchronized Registration registerNlriParser(final Class<? extends AddressFamily> afi, final Class<? extends SubsequentAddressFamily> safi, final NlriParser parser, final NextHopParserSerializer nextHopSerializer, final Class<? extends CNextHop> cnextHopClass, final Class<? extends CNextHop>... cnextHopClassList) {
final BgpTableType key = createKey(afi, safi);
final NlriParser prev = this.handlers.get(key);
checkState(prev == null, "AFI/SAFI is already bound to parser " + prev);
this.handlers.put(key, parser);
this.nextHopParsers.put(key, nextHopSerializer);
if (cnextHopClass != null) {
final Entry<Class<? extends CNextHop>, BgpTableType> nhKey = new SimpleEntry<>(cnextHopClass, key);
this.nextHopSerializers.put(nhKey, nextHopSerializer);
for (final Class<? extends CNextHop> cnextHop : cnextHopClassList) {
final Entry<Class<? extends CNextHop>, BgpTableType> nhKeys = new SimpleEntry<>(cnextHop, key);
this.nextHopSerializers.put(nhKeys, nextHopSerializer);
}
}
final Object lock = this;
return new AbstractRegistration() {
@Override
protected void removeRegistration() {
synchronized (lock) {
SimpleNlriRegistry.this.handlers.remove(key);
SimpleNlriRegistry.this.nextHopParsers.remove(key);
if (cnextHopClass != null) {
final Entry<Class<? extends CNextHop>, BgpTableType> nhKey = new SimpleEntry<>(cnextHopClass, key);
SimpleNlriRegistry.this.nextHopSerializers.remove(nhKey);
for (final Class<? extends CNextHop> cnextHop : cnextHopClassList) {
final Entry<Class<? extends CNextHop>, BgpTableType> nhKeys = new SimpleEntry<>(cnextHop, key);
SimpleNlriRegistry.this.nextHopSerializers.remove(nhKeys);
}
}
}
}
};
}
Aggregations