Search in sources :

Example 1 with BGPOpenMessageParser

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));
}
Also used : BGPOpenMessageParser(org.opendaylight.protocol.bgp.parser.impl.message.BGPOpenMessageParser) BGPNotificationMessageParser(org.opendaylight.protocol.bgp.parser.impl.message.BGPNotificationMessageParser) AddressFamilyRegistry(org.opendaylight.protocol.bgp.parser.spi.AddressFamilyRegistry) SubsequentAddressFamilyRegistry(org.opendaylight.protocol.bgp.parser.spi.SubsequentAddressFamilyRegistry) BGPUpdateMessageParser(org.opendaylight.protocol.bgp.parser.impl.message.BGPUpdateMessageParser) Notify(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Notify) BGPRouteRefreshMessageParser(org.opendaylight.protocol.bgp.parser.impl.message.BGPRouteRefreshMessageParser) SubsequentAddressFamilyRegistry(org.opendaylight.protocol.bgp.parser.spi.SubsequentAddressFamilyRegistry) BGPKeepAliveMessageParser(org.opendaylight.protocol.bgp.parser.impl.message.BGPKeepAliveMessageParser) RouteRefresh(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.RouteRefresh) Keepalive(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Keepalive) Update(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Update) Open(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Open)

Example 2 with BGPOpenMessageParser

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());
}
Also used : BGPOpenMessageParser(org.opendaylight.protocol.bgp.parser.impl.message.BGPOpenMessageParser) OptionalCapabilitiesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.OptionalCapabilitiesBuilder) OpenBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.OpenBuilder) CParameters1(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.CParameters1) BgpParameters(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.BgpParameters) BgpParametersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.BgpParametersBuilder) ProtocolVersion(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.ProtocolVersion) ByteBuf(io.netty.buffer.ByteBuf) AsNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber) OptionalCapabilities(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.OptionalCapabilities) As4BytesCapabilityBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.optional.capabilities.c.parameters.As4BytesCapabilityBuilder) Open(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Open) CParametersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.optional.capabilities.CParametersBuilder) CParameters1Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.CParameters1Builder) GracefulRestartCapabilityBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.GracefulRestartCapabilityBuilder) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address) Test(org.junit.Test)

Aggregations

BGPOpenMessageParser (org.opendaylight.protocol.bgp.parser.impl.message.BGPOpenMessageParser)2 Open (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Open)2 ByteBuf (io.netty.buffer.ByteBuf)1 Test (org.junit.Test)1 BGPKeepAliveMessageParser (org.opendaylight.protocol.bgp.parser.impl.message.BGPKeepAliveMessageParser)1 BGPNotificationMessageParser (org.opendaylight.protocol.bgp.parser.impl.message.BGPNotificationMessageParser)1 BGPRouteRefreshMessageParser (org.opendaylight.protocol.bgp.parser.impl.message.BGPRouteRefreshMessageParser)1 BGPUpdateMessageParser (org.opendaylight.protocol.bgp.parser.impl.message.BGPUpdateMessageParser)1 AddressFamilyRegistry (org.opendaylight.protocol.bgp.parser.spi.AddressFamilyRegistry)1 SubsequentAddressFamilyRegistry (org.opendaylight.protocol.bgp.parser.spi.SubsequentAddressFamilyRegistry)1 AsNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber)1 Ipv4Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)1 Keepalive (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Keepalive)1 Notify (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Notify)1 OpenBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.OpenBuilder)1 ProtocolVersion (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.ProtocolVersion)1 Update (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Update)1 BgpParameters (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.BgpParameters)1 BgpParametersBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.BgpParametersBuilder)1 OptionalCapabilities (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.OptionalCapabilities)1