Search in sources :

Example 1 with BgpTableType

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.BgpTableType in project bgpcep by opendaylight.

the class TableTypeActivatorTest method testActivator.

@Test
public void testActivator() {
    final TableTypeActivator tableTypeActivator = new TableTypeActivator();
    final SimpleBGPTableTypeRegistryProvider registry = new SimpleBGPTableTypeRegistryProvider();
    tableTypeActivator.startBGPTableTypeRegistryProvider(registry);
    final Optional<Class<? extends AfiSafiType>> afiSafiType = registry.getAfiSafiType(IPV4);
    Assert.assertEquals(IPV4LABELLEDUNICAST.class, afiSafiType.get());
    final Optional<Class<? extends AfiSafiType>> afiSafiType2 = registry.getAfiSafiType(IPV6);
    Assert.assertEquals(IPV6LABELLEDUNICAST.class, afiSafiType2.get());
    final Optional<BgpTableType> tableType = registry.getTableType(IPV4LABELLEDUNICAST.class);
    Assert.assertEquals(IPV4, tableType.get());
    final Optional<BgpTableType> tableType2 = registry.getTableType(IPV6LABELLEDUNICAST.class);
    Assert.assertEquals(IPV6, tableType2.get());
    tableTypeActivator.stopBGPTableTypeRegistryProvider();
    tableTypeActivator.close();
}
Also used : BgpTableType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.BgpTableType) SimpleBGPTableTypeRegistryProvider(org.opendaylight.protocol.bgp.openconfig.spi.SimpleBGPTableTypeRegistryProvider) AfiSafiType(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.AfiSafiType) Test(org.junit.Test)

Example 2 with BgpTableType

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.BgpTableType in project bgpcep by opendaylight.

the class TableTypeTest method testTableTypes.

@Test
public void testTableTypes() {
    final BgpTableType tt1 = new BgpTableTypeImpl(Ipv4AddressFamily.class, MplsLabeledVpnSubsequentAddressFamily.class);
    final BgpTableType tt2 = new BgpTableTypeImpl(Ipv6AddressFamily.class, MplsLabeledVpnSubsequentAddressFamily.class);
    try {
        new BgpTableTypeImpl(null, MplsLabeledVpnSubsequentAddressFamily.class);
        fail("Null AFI!");
    } catch (final NullPointerException e) {
        assertEquals("Address family may not be null", e.getMessage());
    }
    try {
        new BgpTableTypeImpl(Ipv6AddressFamily.class, null);
        fail("Null SAFI!");
    } catch (final NullPointerException e) {
        assertEquals("Subsequent address family may not be null", e.getMessage());
    }
    assertNotEquals(tt1, tt2);
    assertNotSame(tt1.hashCode(), tt2.hashCode());
    assertEquals(tt1.toString(), tt1.toString());
    assertNotSame(tt1.getAfi(), tt2.getAfi());
    assertEquals(tt1.getSafi(), tt2.getSafi());
}
Also used : BgpTableType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.BgpTableType) Test(org.junit.Test)

Example 3 with BgpTableType

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.BgpTableType 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 4 with BgpTableType

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.BgpTableType in project bgpcep by opendaylight.

the class SimpleNlriRegistry method convertMpReachToMpUnReach.

@Override
public Optional<MpUnreachNlri> convertMpReachToMpUnReach(final MpReachNlri mpReachNlri, final MpUnreachNlri mpUnreachNlri) {
    if (mpUnreachNlri == null) {
        return Optional.of(new MpUnreachNlriBuilder().setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(mpReachNlri.getAdvertizedRoutes().getDestinationType()).build()).build());
    }
    final BgpTableType key = createKey(mpUnreachNlri.getAfi(), mpUnreachNlri.getSafi());
    final NlriParser parser = this.handlers.get(key);
    if (parser == null) {
        LOG.debug("Parser for {} not found", key);
        return Optional.empty();
    }
    final MpUnreachNlriBuilder builder = new MpUnreachNlriBuilder(mpUnreachNlri);
    return parser.convertMpReachToMpUnReach(mpReachNlri, builder) ? Optional.of(builder.build()) : Optional.empty();
}
Also used : BgpTableType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.BgpTableType) WithdrawnRoutesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.unreach.mp.unreach.nlri.WithdrawnRoutesBuilder) NlriParser(org.opendaylight.protocol.bgp.parser.spi.NlriParser) MpUnreachNlriBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.unreach.MpUnreachNlriBuilder)

Example 5 with BgpTableType

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.BgpTableType in project bgpcep by opendaylight.

the class UtilsTest method testMultiprotocolCapabilitiesUtil.

@Test
public void testMultiprotocolCapabilitiesUtil() throws BGPParsingException {
    final byte[] bytes = new byte[] { 0, 1, 0, 1 };
    final ByteBuf bytesBuf = Unpooled.copiedBuffer(bytes);
    final BgpTableType parsedAfiSafi = MultiprotocolCapabilitiesUtil.parseMPAfiSafi(bytesBuf, this.afiReg, this.safiReg).get();
    assertEquals(Ipv4AddressFamily.class, parsedAfiSafi.getAfi());
    assertEquals(UnicastSubsequentAddressFamily.class, parsedAfiSafi.getSafi());
    final ByteBuf serializedAfiSafi = Unpooled.buffer(4);
    MultiprotocolCapabilitiesUtil.serializeMPAfiSafi(this.afiReg, this.safiReg, Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class, serializedAfiSafi);
    assertArrayEquals(bytes, serializedAfiSafi.array());
}
Also used : BgpTableType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.BgpTableType) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Aggregations

BgpTableType (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.BgpTableType)24 Test (org.junit.Test)16 BgpTableTypeImpl (org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl)12 ArrayList (java.util.ArrayList)11 BgpTableType (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.BgpTableType)9 ByteBuf (io.netty.buffer.ByteBuf)8 AfiSafi (org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.AfiSafi)7 HashMap (java.util.HashMap)5 AfiSafiType (org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.AfiSafiType)5 Ipv4AddressFamily (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.Ipv4AddressFamily)5 UnicastSubsequentAddressFamily (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.UnicastSubsequentAddressFamily)5 HashSet (java.util.HashSet)4 PathSelectionMode (org.opendaylight.protocol.bgp.mode.api.PathSelectionMode)4 SimpleBGPTableTypeRegistryProvider (org.opendaylight.protocol.bgp.openconfig.spi.SimpleBGPTableTypeRegistryProvider)4 BgpParameters (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.BgpParameters)4 OptionalCapabilities (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.OptionalCapabilities)4 AddressFamilies (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.add.path.capability.AddressFamilies)4 BGPDocumentedException (org.opendaylight.protocol.bgp.parser.BGPDocumentedException)3 NlriParser (org.opendaylight.protocol.bgp.parser.spi.NlriParser)3 BgpNeighborAddPathsConfig (org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.BgpNeighborAddPathsConfig)3