use of org.opendaylight.protocol.bgp.parser.impl.message.BGPOpenMessageParser in project bgpcep by opendaylight.
the class BGPActivator method registerMessageParsers.
private static void registerMessageParsers(final List<AutoCloseable> regs, final BGPExtensionProviderContext context) {
final BGPOpenMessageParser omp = new BGPOpenMessageParser(context.getParameterRegistry());
regs.add(context.registerMessageParser(BGPOpenMessageParser.TYPE, omp));
regs.add(context.registerMessageSerializer(Open.class, omp));
final BGPUpdateMessageParser ump = new BGPUpdateMessageParser(context.getAttributeRegistry());
regs.add(context.registerMessageParser(BGPUpdateMessageParser.TYPE, ump));
regs.add(context.registerMessageSerializer(Update.class, ump));
final BGPNotificationMessageParser nmp = new BGPNotificationMessageParser();
regs.add(context.registerMessageParser(BGPNotificationMessageParser.TYPE, nmp));
regs.add(context.registerMessageSerializer(Notify.class, nmp));
final BGPKeepAliveMessageParser kamp = new BGPKeepAliveMessageParser();
regs.add(context.registerMessageParser(BGPKeepAliveMessageParser.TYPE, kamp));
regs.add(context.registerMessageSerializer(Keepalive.class, kamp));
final AddressFamilyRegistry afiReg = context.getAddressFamilyRegistry();
final SubsequentAddressFamilyRegistry safiReg = context.getSubsequentAddressFamilyRegistry();
final BGPRouteRefreshMessageParser rrmp = new BGPRouteRefreshMessageParser(afiReg, safiReg);
regs.add(context.registerMessageParser(BGPRouteRefreshMessageParser.TYPE, rrmp));
regs.add(context.registerMessageSerializer(RouteRefresh.class, rrmp));
}
use of org.opendaylight.protocol.bgp.parser.impl.message.BGPOpenMessageParser in project bgpcep by opendaylight.
the class OpenTest method testSerializeOpen.
@Test
public void testSerializeOpen() throws Exception {
final List<OptionalCapabilities> optionalCapas = Lists.newArrayList();
final OptionalCapabilities optionalCapabilitiesBuilder = new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(new AsNumber(1000L)).build()).addAugmentation(CParameters1.class, new CParameters1Builder().setGracefulRestartCapability(new GracefulRestartCapabilityBuilder().setRestartFlags(new GracefulRestartCapability.RestartFlags(false)).setRestartTime(0).setTables(Collections.emptyList()).build()).build()).build()).build();
optionalCapas.add(optionalCapabilitiesBuilder);
final List<BgpParameters> tlvs = Lists.newArrayList(new BgpParametersBuilder().setOptionalCapabilities(optionalCapas).build());
final Open open = new OpenBuilder().setBgpIdentifier(new Ipv4Address("127.0.0.1")).setMyAsNumber(30).setHoldTimer(3).setVersion(new ProtocolVersion((short) 4)).setBgpParameters(tlvs).build();
final ByteBuf msg = Unpooled.buffer();
new BGPOpenMessageParser(ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getParameterRegistry()).serializeMessage(open, msg);
final byte[] temp = ByteArray.cutBytes(ByteArray.getAllBytes(msg), 19);
final Open openResult = new BGPOpenMessageParser(ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getParameterRegistry()).parseMessageBody(Unpooled.copiedBuffer(temp), temp.length);
assertEquals(open.getBgpIdentifier(), openResult.getBgpIdentifier());
assertEquals(open.getHoldTimer(), openResult.getHoldTimer());
assertEquals(open.getMyAsNumber(), openResult.getMyAsNumber());
boolean grace = false;
if (openResult.getBgpParameters().get(0).getOptionalCapabilities().get(0).getCParameters().getAs4BytesCapability() != null) {
grace = true;
}
assertEquals(open.getBgpParameters().get(0).getOptionalCapabilities().get(0).getCParameters().getAs4BytesCapability(), openResult.getBgpParameters().get(0).getOptionalCapabilities().get(!grace ? 1 : 0).getCParameters().getAs4BytesCapability());
assertEquals(open.getBgpParameters().get(0).getOptionalCapabilities().get(0).getCParameters().getAugmentation(CParameters1.class).getGracefulRestartCapability(), openResult.getBgpParameters().get(0).getOptionalCapabilities().get(grace ? 1 : 0).getCParameters().getAugmentation(CParameters1.class).getGracefulRestartCapability());
}
Aggregations