use of org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl in project bgpcep by opendaylight.
the class LUNlriParser method parseNlri.
@Override
public void parseNlri(@Nonnull final ByteBuf nlri, @Nonnull final MpUnreachNlriBuilder builder, @Nullable final PeerSpecificParserConstraint constraint) throws BGPParsingException {
if (!nlri.isReadable()) {
return;
}
final Class<? extends AddressFamily> afi = builder.getAfi();
final boolean mPathSupported = MultiPathSupportUtil.isTableTypeSupported(constraint, new BgpTableTypeImpl(builder.getAfi(), builder.getSafi()));
final List<CLabeledUnicastDestination> dst = parseNlri(nlri, afi, mPathSupported);
DestinationType destination = null;
if (afi == Ipv4AddressFamily.class) {
destination = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev171207.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLabeledUnicastCaseBuilder().setDestinationLabeledUnicast(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev171207.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.labeled.unicast._case.DestinationLabeledUnicastBuilder().setCLabeledUnicastDestination(dst).build()).build();
} else if (afi == Ipv6AddressFamily.class) {
destination = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev171207.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv6LabeledUnicastCaseBuilder().setDestinationIpv6LabeledUnicast(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev171207.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.ipv6.labeled.unicast._case.DestinationIpv6LabeledUnicastBuilder().setCLabeledUnicastDestination(dst).build()).build();
}
builder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(destination).build());
}
use of org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl in project bgpcep by opendaylight.
the class AbstractRIBTestSetup method mockRib.
public void mockRib() throws Exception {
final RIBExtensionProviderContext context = new SimpleRIBExtensionProviderContext();
final ModuleInfoBackedContext strategy = createClassLoadingStrategy();
final SchemaContext schemaContext = strategy.tryToCreateSchemaContext().get();
this.codecFactory = createCodecFactory(strategy, schemaContext);
final List<BgpTableType> localTables = new ArrayList<>();
localTables.add(new BgpTableTypeImpl(AFI, SAFI));
this.a1 = new RIBActivator();
this.a1.startRIBExtensionProvider(context);
final CodecsRegistryImpl codecsRegistry = CodecsRegistryImpl.create(this.codecFactory, GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy());
mockedMethods();
doReturn(mock(ClusterSingletonServiceRegistration.class)).when(this.clusterSingletonServiceProvider).registerClusterSingletonService(any(ClusterSingletonService.class));
this.rib = new RIBImpl(new RibId("test"), new AsNumber(5L), RIB_ID, context, this.dispatcher, codecsRegistry, this.dom, getDataBroker(), this.policies, this.peerTracker, localTables, Collections.singletonMap(new TablesKey(AFI, SAFI), BasePathSelectionModeFactory.createBestPathSelectionStrategy(this.peerTracker)));
this.rib.onGlobalContextUpdated(schemaContext);
this.ribSupport = getRib().getRibSupportContext().getRIBSupport(KEY);
}
use of org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl in project bgpcep by opendaylight.
the class OpenConfigMappingUtilTest method toPathSelectionMode.
@Test
public void toPathSelectionMode() {
final List<AfiSafi> families = new ArrayList<>();
families.add(new AfiSafiBuilder().setAfiSafiName(IPV4UNICAST.class).addAugmentation(GlobalAddPathsConfig.class, new GlobalAddPathsConfigBuilder().setSendMax(Shorts.checkedCast(N_PATHS)).build()).build());
families.add(new AfiSafiBuilder().setAfiSafiName(IPV6UNICAST.class).addAugmentation(GlobalAddPathsConfig.class, new GlobalAddPathsConfigBuilder().setSendMax(Shorts.checkedCast(ALL_PATHS)).build()).build());
final Map<BgpTableType, PathSelectionMode> result = OpenConfigMappingUtil.toPathSelectionMode(families, this.tableTypeRegistry, PEER_TRACKER);
final Map<BgpTableType, PathSelectionMode> expected = new HashMap<>();
expected.put(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class), ADD_PATH_BEST_N_PATH_SELECTION);
expected.put(new BgpTableTypeImpl(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class), ADD_PATH_BEST_ALL_PATH_SELECTION);
assertEquals(expected.get(0), result.get(0));
assertEquals(expected.get(1), result.get(1));
}
use of org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl in project bgpcep by opendaylight.
the class EventBusRegistration method sendMessage.
private static void sendMessage(final BGPSessionListener listener, final Notification message) {
if (BGPMock.CONNECTION_LOST_MAGIC_MSG.equals(message)) {
listener.onSessionTerminated(null, new BGPTerminationReason(BGPError.CEASE));
} else if (message instanceof Open) {
final Set<BgpTableType> tts = Sets.newHashSet();
final List<AddressFamilies> addPathCapabilitiesList = Lists.newArrayList();
for (final BgpParameters param : ((Open) message).getBgpParameters()) {
for (final OptionalCapabilities capa : param.getOptionalCapabilities()) {
final CParameters cParam = capa.getCParameters();
if (cParam.getAugmentation(CParameters1.class) == null) {
continue;
}
if (cParam.getAugmentation(CParameters1.class).getMultiprotocolCapability() != null) {
final MultiprotocolCapability p = cParam.getAugmentation(CParameters1.class).getMultiprotocolCapability();
LOG.debug("Adding open parameter {}", p);
final BgpTableType type = new BgpTableTypeImpl(p.getAfi(), p.getSafi());
tts.add(type);
} else if (cParam.getAugmentation(CParameters1.class).getAddPathCapability() != null) {
final AddPathCapability addPathCap = cParam.getAugmentation(CParameters1.class).getAddPathCapability();
addPathCapabilitiesList.addAll(addPathCap.getAddressFamilies());
}
}
}
listener.onSessionUp(new MockBGPSession(tts));
} else if (!(message instanceof Keepalive)) {
try {
listener.onMessage(new MockBGPSession(), message);
} catch (BGPDocumentedException e) {
LOG.warn("Exception encountered while handling message", e);
}
}
}
use of org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl in project bgpcep by opendaylight.
the class BGPMessageParserMockTest method testGetOpenMessage.
@Test
public void testGetOpenMessage() throws BGPParsingException, BGPDocumentedException {
final Map<ByteBuf, Notification> openMap = Maps.newHashMap();
final Set<BgpTableType> type = Sets.newHashSet();
type.add(new BgpTableTypeImpl(Ipv4AddressFamily.class, MplsLabeledVpnSubsequentAddressFamily.class));
final List<BgpParameters> params = Lists.newArrayList();
final CParameters par = new CParametersBuilder().addAugmentation(CParameters1.class, new CParameters1Builder().setMultiprotocolCapability(new MultiprotocolCapabilityBuilder().setAfi(Ipv4AddressFamily.class).setSafi(MplsLabeledVpnSubsequentAddressFamily.class).build()).build()).build();
params.add(new BgpParametersBuilder().setOptionalCapabilities(Lists.newArrayList(new OptionalCapabilitiesBuilder().setCParameters(par).build())).build());
final byte[] input = new byte[] { 5, 8, 13, 21 };
openMap.put(Unpooled.copiedBuffer(input), new OpenBuilder().setMyAsNumber(30).setHoldTimer(30).setBgpParameters(params).setVersion(new ProtocolVersion((short) 4)).build());
final BGPMessageParserMock mockParser = new BGPMessageParserMock(openMap);
final Set<BgpTableType> result = Sets.newHashSet();
for (final BgpParameters p : ((Open) mockParser.parseMessage(Unpooled.copiedBuffer(input), null)).getBgpParameters()) {
for (final OptionalCapabilities capa : p.getOptionalCapabilities()) {
final CParameters cp = capa.getCParameters();
if (cp.getAugmentation(CParameters1.class) != null && cp.getAugmentation(CParameters1.class).getMultiprotocolCapability() != null) {
final BgpTableType t = new BgpTableTypeImpl(cp.getAugmentation(CParameters1.class).getMultiprotocolCapability().getAfi(), cp.getAugmentation(CParameters1.class).getMultiprotocolCapability().getSafi());
result.add(t);
}
}
}
assertEquals(type, result);
}
Aggregations