Search in sources :

Example 1 with OpenBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.OpenBuilder in project bgpcep by opendaylight.

the class APITest method testAsNumberUtil.

@Test
public void testAsNumberUtil() {
    final List<BgpParameters> params = new ArrayList<>();
    final List<OptionalCapabilities> capas = new ArrayList<>();
    capas.add(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().addAugmentation(new CParameters1Builder().setMultiprotocolCapability(new MultiprotocolCapabilityBuilder().build()).build()).build()).build());
    capas.add(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(new AsNumber(Uint32.valueOf(35))).build()).build()).build());
    params.add(new BgpParametersBuilder().setOptionalCapabilities(capas).build());
    final Open open1 = new OpenBuilder().setBgpParameters(params).build();
    assertEquals(35L, AsNumberUtil.advertizedAsNumber(open1).getValue().longValue());
    final Open open2 = new OpenBuilder().setMyAsNumber(Uint16.valueOf(10)).build();
    assertEquals(10, AsNumberUtil.advertizedAsNumber(open2).getValue().intValue());
}
Also used : OptionalCapabilitiesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.OptionalCapabilitiesBuilder) MultiprotocolCapabilityBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.MultiprotocolCapabilityBuilder) OpenBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.OpenBuilder) ArrayList(java.util.ArrayList) BgpParameters(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.BgpParameters) BgpParametersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.BgpParametersBuilder) 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.rev200120.open.message.bgp.parameters.OptionalCapabilities) As4BytesCapabilityBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.optional.capabilities.c.parameters.As4BytesCapabilityBuilder) Open(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Open) CParametersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.optional.capabilities.CParametersBuilder) CParameters1Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.CParameters1Builder) Test(org.junit.Test)

Example 2 with OpenBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.OpenBuilder 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);
}
Also used : HashMap(java.util.HashMap) Ipv4AddressFamily(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.Ipv4AddressFamily) ArrayList(java.util.ArrayList) CParameters(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.optional.capabilities.CParameters) ByteBuf(io.netty.buffer.ByteBuf) BgpParameters(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.BgpParameters) ProtocolVersion(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.ProtocolVersion) CParameters1(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.CParameters1) Notification(org.opendaylight.yangtools.yang.binding.Notification) Open(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Open) CParametersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.optional.capabilities.CParametersBuilder) HashSet(java.util.HashSet) BgpTableType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.BgpTableType) OptionalCapabilitiesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.OptionalCapabilitiesBuilder) MplsLabeledVpnSubsequentAddressFamily(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.MplsLabeledVpnSubsequentAddressFamily) MultiprotocolCapabilityBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.MultiprotocolCapabilityBuilder) OpenBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.OpenBuilder) BgpParametersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.BgpParametersBuilder) OptionalCapabilities(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.OptionalCapabilities) CParameters1Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.CParameters1Builder) BgpTableTypeImpl(org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl) Test(org.junit.Test)

Example 3 with OpenBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.OpenBuilder in project bgpcep by opendaylight.

the class ParserTest method testOpenMessage.

@Test
public void testOpenMessage() throws BGPParsingException, BGPDocumentedException {
    final Notification open = new OpenBuilder().setMyAsNumber(Uint16.valueOf(100)).setHoldTimer(Uint16.valueOf(180)).setBgpIdentifier(new Ipv4AddressNoZone("20.20.20.20")).setVersion(new ProtocolVersion(Uint8.valueOf(4))).build();
    final ByteBuf bytes = Unpooled.buffer();
    ParserTest.reg.serializeMessage(open, bytes);
    assertArrayEquals(OPEN_BMSG, ByteArray.getAllBytes(bytes));
    final Notification m = ParserTest.reg.parseMessage(Unpooled.copiedBuffer(bytes), null);
    assertThat(m, instanceOf(Open.class));
    final Open mo = (Open) m;
    assertEquals(100, mo.getMyAsNumber().intValue());
    assertEquals(180, mo.getHoldTimer().intValue());
    assertEquals(new Ipv4Address("20.20.20.20"), mo.getBgpIdentifier());
    assertNull(mo.getBgpParameters());
}
Also used : OpenBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.OpenBuilder) Ipv4AddressNoZone(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone) ProtocolVersion(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.ProtocolVersion) ByteBuf(io.netty.buffer.ByteBuf) Notification(org.opendaylight.yangtools.yang.binding.Notification) Open(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Open) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address) Test(org.junit.Test)

Example 4 with OpenBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.OpenBuilder 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());
}
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.rev200120.open.message.bgp.parameters.OptionalCapabilitiesBuilder) OpenBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.OpenBuilder) Ipv4AddressNoZone(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone) ArrayList(java.util.ArrayList) ProtocolVersion(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.ProtocolVersion) BgpParametersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.BgpParametersBuilder) 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.rev200120.open.message.bgp.parameters.OptionalCapabilities) As4BytesCapabilityBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.optional.capabilities.c.parameters.As4BytesCapabilityBuilder) Open(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Open) CParametersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.optional.capabilities.CParametersBuilder) Test(org.junit.Test)

Example 5 with OpenBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.OpenBuilder in project bgpcep by opendaylight.

the class PeerTest method mockSession.

private void mockSession() {
    final EventLoop eventLoop = mock(EventLoop.class);
    final Channel channel = mock(Channel.class);
    final ChannelPipeline pipeline = mock(ChannelPipeline.class);
    doReturn(null).when(eventLoop).schedule(any(Runnable.class), any(long.class), any(TimeUnit.class));
    doReturn(eventLoop).when(channel).eventLoop();
    doReturn(Boolean.TRUE).when(channel).isWritable();
    doReturn(null).when(channel).close();
    doReturn(pipeline).when(channel).pipeline();
    doCallRealMethod().when(channel).toString();
    doReturn(pipeline).when(pipeline).addLast(any(ChannelHandler.class));
    doReturn(new DefaultChannelPromise(channel)).when(channel).writeAndFlush(any(Notification.class));
    doReturn(new InetSocketAddress("localhost", 12345)).when(channel).remoteAddress();
    doReturn(new InetSocketAddress("localhost", 12345)).when(channel).localAddress();
    final List<BgpParameters> params = Lists.newArrayList(new BgpParametersBuilder().setOptionalCapabilities(Lists.newArrayList(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().addAugmentation(new CParameters1Builder().setMultiprotocolCapability(new MultiprotocolCapabilityBuilder().setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).build()).build()).build()).build())).build());
    final Open openObj = new OpenBuilder().setBgpIdentifier(new Ipv4AddressNoZone("1.1.1.1")).setHoldTimer(Uint16.valueOf(50)).setMyAsNumber(Uint16.valueOf(72)).setBgpParameters(params).build();
    this.session = new BGPSessionImpl(this.classic, channel, openObj, 30, null);
    this.session.setChannelExtMsgCoder(openObj);
}
Also used : OptionalCapabilitiesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.OptionalCapabilitiesBuilder) MultiprotocolCapabilityBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.MultiprotocolCapabilityBuilder) OpenBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.OpenBuilder) Ipv4AddressNoZone(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone) InetSocketAddress(java.net.InetSocketAddress) Channel(io.netty.channel.Channel) ChannelHandler(io.netty.channel.ChannelHandler) BgpParameters(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.BgpParameters) BgpParametersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.BgpParametersBuilder) ChannelPipeline(io.netty.channel.ChannelPipeline) Notification(org.opendaylight.yangtools.yang.binding.Notification) Open(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Open) CParametersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.optional.capabilities.CParametersBuilder) CParameters1Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.CParameters1Builder) EventLoop(io.netty.channel.EventLoop) DefaultChannelPromise(io.netty.channel.DefaultChannelPromise) TimeUnit(java.util.concurrent.TimeUnit) UnicastSubsequentAddressFamily(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.UnicastSubsequentAddressFamily)

Aggregations

OpenBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.OpenBuilder)21 Test (org.junit.Test)17 Ipv4AddressNoZone (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone)12 Open (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Open)12 ArrayList (java.util.ArrayList)11 ProtocolVersion (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.ProtocolVersion)11 BgpParametersBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.BgpParametersBuilder)11 OptionalCapabilitiesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.OptionalCapabilitiesBuilder)11 CParametersBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.optional.capabilities.CParametersBuilder)11 ByteBuf (io.netty.buffer.ByteBuf)10 CParameters1Builder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.CParameters1Builder)10 Notification (org.opendaylight.yangtools.yang.binding.Notification)10 OptionalCapabilities (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.OptionalCapabilities)9 MultiprotocolCapabilityBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.MultiprotocolCapabilityBuilder)9 BgpParameters (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.BgpParameters)8 AsNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber)7 As4BytesCapabilityBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.optional.capabilities.c.parameters.As4BytesCapabilityBuilder)7 Before (org.junit.Before)6 OpenBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.OpenBuilder)6 OpenMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.message.OpenMessageBuilder)6