use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.BgpParameters in project bgpcep by opendaylight.
the class BGPOpenMessageParser method normalSerializeParameters.
private ByteBuf normalSerializeParameters(final List<BgpParameters> params) {
final ByteBuf buffer = Unpooled.buffer();
for (final BgpParameters param : params) {
final Optional<ParameterSerializer> optSer = reg.findSerializer(param);
if (optSer.isPresent()) {
try {
optSer.get().serializeParameter(param, buffer);
} catch (ParameterLengthOverflowException e) {
LOG.debug("Forcing extended parameter serialization", e);
return null;
}
} else {
LOG.debug("Ingnoring unregistered parameter {}", param);
}
}
final int length = buffer.writerIndex();
if (length > Values.UNSIGNED_BYTE_MAX_VALUE) {
LOG.debug("Final parameter size is {}, forcing extended serialization", length);
return null;
}
return buffer;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.BgpParameters in project bgpcep by opendaylight.
the class BGPOpenMessageParser method serializeParameters.
private void serializeParameters(final List<BgpParameters> params, final ByteBuf msgBody) {
if (params == null || params.isEmpty()) {
msgBody.writeByte(0);
return;
}
final ByteBuf normal = normalSerializeParameters(params);
if (normal != null) {
final int length = normal.writerIndex();
verify(length <= Values.UNSIGNED_BYTE_MAX_VALUE);
msgBody.writeByte(length);
msgBody.writeBytes(normal);
return;
}
final ByteBuf buffer = Unpooled.buffer();
for (final BgpParameters param : params) {
final Optional<ParameterSerializer> optSer = reg.findSerializer(param);
if (optSer.isPresent()) {
optSer.get().serializeExtendedParameter(param, buffer);
} else {
LOG.debug("Ignoring unregistered parameter {}", param);
}
}
final int length = buffer.writerIndex();
checkState(length <= Values.UNSIGNED_SHORT_MAX_VALUE);
// The non-extended Optional Parameters Length field MUST be set to 255
msgBody.writeByte(Values.UNSIGNED_BYTE_MAX_VALUE);
// The subsequent one-octet field, that in the non-extended format would
// be the first Optional Parameter Type field, MUST be set to 255
msgBody.writeByte(OPT_PARAM_EXT_PARAM);
// Extended Optional Parameters Length
msgBody.writeShort(length);
msgBody.writeBytes(buffer);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.BgpParameters in project bgpcep by opendaylight.
the class BGPMessageParserMockTest method testGetOpenMessage.
@Test
public void testGetOpenMessage() throws BGPParsingException, BGPDocumentedException {
final Map<ByteBuf, Notification> openMap = new HashMap<>();
final Set<BgpTableType> type = new HashSet<>();
type.add(new BgpTableTypeImpl(Ipv4AddressFamily.class, MplsLabeledVpnSubsequentAddressFamily.class));
final List<BgpParameters> params = new ArrayList<>();
final CParameters par = new CParametersBuilder().addAugmentation(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(Uint16.valueOf(30)).setHoldTimer(Uint16.valueOf(30)).setBgpParameters(params).setVersion(new ProtocolVersion(Uint8.valueOf(4))).build());
final BGPMessageParserMock mockParser = new BGPMessageParserMock(openMap);
final Set<BgpTableType> result = new HashSet<>();
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.augmentation(CParameters1.class) != null && cp.augmentation(CParameters1.class).getMultiprotocolCapability() != null) {
final BgpTableType t = new BgpTableTypeImpl(cp.augmentation(CParameters1.class).getMultiprotocolCapability().getAfi(), cp.augmentation(CParameters1.class).getMultiprotocolCapability().getSafi());
result.add(t);
}
}
}
assertEquals(type, result);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.BgpParameters in project bgpcep by opendaylight.
the class SimpleRegistryTest method testSimpleParameter.
@Test
public void testSimpleParameter() throws Exception {
final ParameterRegistry paramReg = this.ctx.getParameterRegistry();
final BgpParameters param = mock(BgpParameters.class);
Mockito.doReturn(BgpParameters.class).when(param).implementedInterface();
assertEquals(Optional.of(activator.paramParser), paramReg.findParser(0));
assertEquals(Optional.of(activator.paramSerializer), paramReg.findSerializer(param));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.BgpParameters in project bgpcep by opendaylight.
the class BGPPeer method setGracefulPreferences.
private synchronized void setGracefulPreferences(final boolean localRestarting, final Set<TablesKey> preservedTables) {
final Set<TablesKey> gracefulTables = this.tables.stream().filter(this::isGracefulRestartAdvertized).collect(Collectors.toSet());
final BgpParameters bgpParameters = GracefulRestartUtil.getGracefulBgpParameters(this.bgpPeer.getBgpFixedCapabilities(), gracefulTables, preservedTables, this.bgpPeer.getGracefulRestartTimer(), localRestarting, Collections.emptySet());
final BGPSessionPreferences oldPrefs = this.rib.getDispatcher().getBGPPeerRegistry().getPeerPreferences(getNeighborAddress());
final BGPSessionPreferences newPrefs = new BGPSessionPreferences(oldPrefs.getMyAs(), oldPrefs.getHoldTime(), oldPrefs.getBgpId(), oldPrefs.getExpectedRemoteAs(), Collections.singletonList(bgpParameters), oldPrefs.getMd5Password());
this.rib.getDispatcher().getBGPPeerRegistry().updatePeerPreferences(getNeighborAddress(), newPrefs);
}
Aggregations