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();
}
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());
}
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);
}
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();
}
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());
}
Aggregations