use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.OptionalCapabilities in project bgpcep by opendaylight.
the class OpenTest method testSerializeLongOpen.
@Test
public void testSerializeLongOpen() throws BGPDocumentedException {
final List<OptionalCapabilities> capabilities = new ArrayList<>();
for (int i = 0; i < 200; ++i) {
capabilities.add(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(new AsNumber(Uint32.valueOf(1000))).build()).build()).build());
}
final Open open = new OpenBuilder().setBgpIdentifier(new Ipv4AddressNoZone("127.0.0.1")).setMyAsNumber(Uint16.valueOf(30)).setHoldTimer(Uint16.valueOf(3)).setVersion(new ProtocolVersion(Uint8.valueOf(4))).setBgpParameters(List.of(new BgpParametersBuilder().setOptionalCapabilities(capabilities).build())).build();
final ByteBuf msg = Unpooled.buffer();
new BGPOpenMessageParser(registry).serializeMessage(open, msg);
assertEquals(1235, msg.readableBytes());
final byte[] temp = ByteArray.cutBytes(ByteArray.getAllBytes(msg), 19);
final Open openResult = new BGPOpenMessageParser(registry).parseMessageBody(Unpooled.copiedBuffer(temp), temp.length, null);
assertEquals(200, openResult.getBgpParameters().get(0).getOptionalCapabilities().size());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.OptionalCapabilities in project bgpcep by opendaylight.
the class StrictBGPPeerRegistry method getAs4BytesCapability.
@Nullable
private static As4BytesCapability getAs4BytesCapability(final List<BgpParameters> prefs) {
for (final BgpParameters param : prefs) {
for (final OptionalCapabilities capa : param.nonnullOptionalCapabilities()) {
final CParameters cParam = capa.getCParameters();
final As4BytesCapability asCapa = cParam.getAs4BytesCapability();
if (asCapa != null) {
return asCapa;
}
}
}
return null;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.OptionalCapabilities in project bgpcep by opendaylight.
the class BgpPeer method getBgpCapabilities.
@SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "https://github.com/spotbugs/spotbugs/issues/811")
private static List<OptionalCapabilities> getBgpCapabilities(final AfiSafis afiSafis, final RIB rib, final BGPTableTypeRegistryConsumer tableTypeRegistry) {
final List<OptionalCapabilities> caps = new ArrayList<>();
caps.add(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(rib.getLocalAs()).build()).build()).build());
caps.add(new OptionalCapabilitiesBuilder().setCParameters(BgpExtendedMessageUtil.EXTENDED_MESSAGE_CAPABILITY).build());
caps.add(new OptionalCapabilitiesBuilder().setCParameters(MultiprotocolCapabilitiesUtil.RR_CAPABILITY).build());
final Collection<AfiSafi> afiSafi = OpenConfigMappingUtil.getAfiSafiWithDefault(afiSafis, false).values();
final List<AddressFamilies> addPathCapability = OpenConfigMappingUtil.toAddPathCapability(afiSafi, tableTypeRegistry);
if (!addPathCapability.isEmpty()) {
caps.add(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().addAugmentation(new CParameters1Builder().setAddPathCapability(new AddPathCapabilityBuilder().setAddressFamilies(addPathCapability).build()).build()).build()).build());
}
final List<BgpTableType> tableTypes = OpenConfigMappingUtil.toTableTypes(afiSafi, tableTypeRegistry);
for (final BgpTableType tableType : tableTypes) {
if (!rib.getLocalTables().contains(tableType)) {
LOG.info("RIB instance does not list {} in its local tables. Incoming data will be dropped.", tableType);
}
caps.add(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().addAugmentation(new CParameters1Builder().setMultiprotocolCapability(new MultiprotocolCapabilityBuilder(tableType).build()).build()).build()).build());
}
return caps;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.OptionalCapabilities in project bgpcep by opendaylight.
the class BGPSessionStateImpl method advertizeCapabilities.
@Override
public synchronized void advertizeCapabilities(final int newHoldTimerValue, final SocketAddress newRemoteAddress, final SocketAddress localAddress, final Set<BgpTableType> tableTypes, final List<BgpParameters> bgpParameters) {
if (bgpParameters != null) {
for (final BgpParameters parameters : bgpParameters) {
for (final OptionalCapabilities optionalCapabilities : parameters.nonnullOptionalCapabilities()) {
final CParameters cParam = optionalCapabilities.getCParameters();
final CParameters1 capabilities = cParam.augmentation(CParameters1.class);
if (capabilities != null) {
final MultiprotocolCapability mc = capabilities.getMultiprotocolCapability();
if (mc != null) {
this.multiProtocolCapability = true;
}
if (capabilities.getGracefulRestartCapability() != null) {
this.gracefulRestartCapability = true;
}
if (capabilities.getAddPathCapability() != null) {
this.addPathCapability = true;
}
if (capabilities.getRouteRefreshCapability() != null) {
this.routerRefreshCapability = true;
}
}
if (cParam.getAs4BytesCapability() != null) {
this.asn32Capability = true;
}
}
}
}
this.holdTimerValue = newHoldTimerValue;
this.remoteAddress = StrictBGPPeerRegistry.getIpAddress(newRemoteAddress);
this.remotePort = new PortNumber(Uint16.valueOf(((InetSocketAddress) newRemoteAddress).getPort()));
this.localPort = new PortNumber(Uint16.valueOf(((InetSocketAddress) localAddress).getPort()));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.OptionalCapabilities in project bgpcep by opendaylight.
the class GracefulRestartUtilTest method getGracefulBgpParametersTest.
@Test
public void getGracefulBgpParametersTest() {
final OptionalCapabilities cap1 = new OptionalCapabilitiesBuilder().setCParameters(BgpExtendedMessageUtil.EXTENDED_MESSAGE_CAPABILITY).build();
final OptionalCapabilities cap2 = new OptionalCapabilitiesBuilder().setCParameters(MultiprotocolCapabilitiesUtil.RR_CAPABILITY).build();
final List<OptionalCapabilities> fixedCaps = new ArrayList<>();
fixedCaps.add(cap1);
fixedCaps.add(cap2);
final Set<TablesKey> gracefulTables = new HashSet<>();
gracefulTables.add(IPV4_KEY);
gracefulTables.add(IPV6_KEY);
final Set<TablesKey> preservedTables = new HashSet<>();
preservedTables.add(IPV4_KEY);
final Map<TablesKey, Boolean> gracefulMap = new HashMap<>();
gracefulMap.put(IPV4_KEY, true);
gracefulMap.put(IPV6_KEY, false);
final OptionalCapabilities expectedGracefulCapability = new OptionalCapabilitiesBuilder().setCParameters(GracefulRestartUtil.getGracefulCapability(gracefulMap, RESTART_TIME, RESTARTING)).build();
final Set<BgpPeerUtil.LlGracefulRestartDTO> llGracefulDTOs = Collections.singleton(new BgpPeerUtil.LlGracefulRestartDTO(IPV4_KEY, STALE_TIME, true));
final OptionalCapabilities expectedLlGracefulCapability = new OptionalCapabilitiesBuilder().setCParameters(GracefulRestartUtil.getLlGracefulCapability(llGracefulDTOs)).build();
final BgpParameters parameters = GracefulRestartUtil.getGracefulBgpParameters(fixedCaps, gracefulTables, preservedTables, RESTART_TIME, RESTARTING, llGracefulDTOs);
final List<OptionalCapabilities> capabilities = parameters.getOptionalCapabilities();
assertTrue(capabilities != null);
assertEquals(4, capabilities.size());
assertTrue(capabilities.contains(cap1));
assertTrue(capabilities.contains(cap2));
assertTrue(capabilities.contains(expectedGracefulCapability));
assertTrue(capabilities.contains(expectedLlGracefulCapability));
}
Aggregations