use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev171204.Uint24 in project bgpcep by opendaylight.
the class LlGracefulCapabilityHandler method serializeCapability.
private ByteBuf serializeCapability(final LlGracefulRestartCapability cap) {
final Map<TablesKey, Tables> tables = cap.getTables();
if (tables == null || tables.isEmpty()) {
return Unpooled.EMPTY_BUFFER;
}
final ByteBuf buffer = Unpooled.buffer(PER_TABLE_SIZE * tables.size());
for (Tables table : tables.values()) {
final Class<? extends AddressFamily> afi = table.getAfi();
final Class<? extends SubsequentAddressFamily> safi = table.getSafi();
final Integer afival = this.afiReg.numberForClass(afi);
checkArgument(afival != null, "Unhandled address family %s", afi);
buffer.writeShort(afival);
final Integer safival = this.safiReg.numberForClass(safi);
checkArgument(safival != null, "Unhandled subsequent address family %s", safi);
buffer.writeByte(safival);
if (table.getAfiFlags() != null && table.getAfiFlags().getForwardingState()) {
buffer.writeByte(AFI_FLAG_FORWARDING_STATE);
} else {
buffer.writeByte(0);
}
final Uint24 staleTime = table.getLongLivedStaleTime();
final int timeval = staleTime != null ? staleTime.getValue().intValue() : 0;
checkArgument(timeval >= 0 && timeval <= MAX_STALE_TIME, "Restart time is %s", staleTime);
buffer.writeMedium(timeval);
}
return buffer;
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev171204.Uint24 in project bgpcep by opendaylight.
the class LlGracefulCapabilityHandlerTest method testLongLivedGracefulCapabilityHandler.
@Test
public void testLongLivedGracefulCapabilityHandler() throws BGPParsingException, BGPDocumentedException {
final byte[] capaBytes = { // header
(byte) 0x47, (byte) 0x0e, // Ipv4 Unicast, afiFlags = false, timer = 10
(byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0a, // Ipv6 Unicast, afiFlags = true, timer = 160
(byte) 0x00, (byte) 0x02, (byte) 0x01, (byte) 0x80, (byte) 0x00, (byte) 0x00, (byte) 0xa0 };
final LlGracefulRestartCapability capability = new LlGracefulRestartCapabilityBuilder().setTables(BindingMap.ordered(new TablesBuilder().setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).setAfiFlags(new Tables.AfiFlags(Boolean.FALSE)).setLongLivedStaleTime(TEN).build(), new TablesBuilder().setAfi(Ipv6AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).setAfiFlags(new Tables.AfiFlags(Boolean.TRUE)).setLongLivedStaleTime(new Uint24(Uint32.valueOf(160))).build())).build();
final CParameters cParameters = new CParametersBuilder().addAugmentation(new CParameters1Builder().setLlGracefulRestartCapability(capability).build()).build();
final ByteBuf buffer = Unpooled.buffer(capaBytes.length);
this.handler.serializeCapability(cParameters, buffer);
assertArrayEquals(capaBytes, buffer.array());
assertEquals(cParameters, this.handler.parseCapability(Unpooled.wrappedBuffer(capaBytes).slice(2, capaBytes.length - 2)));
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev171204.Uint24 in project bgpcep by opendaylight.
the class GracefulRestartUtil method getLlGracefulTimers.
static Map<TablesKey, Integer> getLlGracefulTimers(final Collection<? extends AfiSafi> afiSafis, final BGPTableTypeRegistryConsumer tableTypeRegistry) {
final Map<TablesKey, Integer> timers = new HashMap<>();
afiSafis.forEach(afiSafi -> {
final GracefulRestart gracefulRestart = afiSafi.getGracefulRestart();
if (gracefulRestart != null) {
final Config gracefulRestartConfig = gracefulRestart.getConfig();
if (gracefulRestartConfig != null) {
final LlGracefulRestart llGracefulRestart;
final Config1 peerAug = gracefulRestartConfig.augmentation(Config1.class);
if (peerAug != null) {
llGracefulRestart = peerAug.getLlGracefulRestart();
} else {
final Config2 neighborAug = gracefulRestartConfig.augmentation(Config2.class);
if (neighborAug != null) {
llGracefulRestart = neighborAug.getLlGracefulRestart();
} else {
return;
}
}
if (llGracefulRestart != null) {
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.ll.graceful.restart.rev181112.afi.safi.ll.graceful.restart.ll.graceful.restart.Config config = llGracefulRestart.getConfig();
if (config != null) {
final Uint24 staleTime = config.getLongLivedStaleTime();
if (staleTime != null && staleTime.getValue().toJava() > 0) {
final TablesKey key = tableTypeRegistry.getTableKey(afiSafi.getAfiSafiName());
if (key != null) {
timers.put(key, staleTime.getValue().intValue());
} else {
LOG.debug("Skipping unsupported afi-safi {}", afiSafi.getAfiSafiName());
}
}
}
}
}
}
});
return timers;
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev171204.Uint24 in project bgpcep by opendaylight.
the class SrAttributeParserTest method testSrCapabilities.
// tools.ietf.org/html/draft-gredler-idr-bgp-ls-segment-routing-ext-00#section-2.1.1
@Test
public void testSrCapabilities() {
final byte[] bytesIsis = { (byte) 0xC0, 0, 0, 0, 10, 4, (byte) 0x89, 0, 4, 1, 2, 3, 4 };
final byte[] bytesOspf = { 0, 0, 0, 0, 10, 4, (byte) 0x89, 0, 4, 1, 2, 3, 4 };
final SrCapabilities capsIsis = new SrCapabilitiesBuilder().setMplsIpv4(Boolean.TRUE).setMplsIpv6(Boolean.TRUE).setSrIpv6(Boolean.FALSE).setSidLabelIndex(new SidCaseBuilder().setSid(Uint32.valueOf(16909060L)).build()).setRangeSize(new Uint24(Uint32.TEN)).build();
final SrCapabilities capsOspf = new SrCapabilitiesBuilder().setMplsIpv4(Boolean.FALSE).setMplsIpv6(Boolean.FALSE).setSrIpv6(Boolean.FALSE).setSidLabelIndex(new SidCaseBuilder().setSid(Uint32.valueOf(16909060L)).build()).setRangeSize(new Uint24(Uint32.TEN)).build();
assertEquals(capsIsis, SrNodeAttributesParser.parseSrCapabilities(Unpooled.wrappedBuffer(bytesIsis), ProtocolId.IsisLevel1));
assertEquals(capsOspf, SrNodeAttributesParser.parseSrCapabilities(Unpooled.wrappedBuffer(bytesIsis), ProtocolId.Ospf));
final ByteBuf encodedIsis = Unpooled.buffer();
final ByteBuf encodedOspf = Unpooled.buffer();
SrNodeAttributesParser.serializeSrCapabilities(capsIsis, encodedIsis);
SrNodeAttributesParser.serializeSrCapabilities(capsOspf, encodedOspf);
assertArrayEquals(bytesIsis, ByteArray.readAllBytes(encodedIsis));
assertArrayEquals(bytesOspf, ByteArray.readAllBytes(encodedOspf));
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev171204.Uint24 in project bgpcep by opendaylight.
the class GracefulRestartUtilTest method getLlGracefulTimersTest.
@Test
public void getLlGracefulTimersTest() {
final List<AfiSafi> afiSafi = new ArrayList<>();
afiSafi.add(new AfiSafiBuilder().setAfiSafiName(IPV4UNICAST.class).setGracefulRestart(new GracefulRestartBuilder().setConfig(new ConfigBuilder().addAugmentation(new Config1Builder().setLlGracefulRestart(new LlGracefulRestartBuilder().setConfig(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.ll.graceful.restart.rev181112.afi.safi.ll.graceful.restart.ll.graceful.restart.ConfigBuilder().setLongLivedStaleTime(new Uint24(Uint32.valueOf(STALE_TIME))).build()).build()).build()).build()).build()).build());
final Map<TablesKey, Integer> llGracefulTimers = GracefulRestartUtil.getLlGracefulTimers(afiSafi, this.tableRegistry);
assertNotNull(llGracefulTimers);
assertEquals(1, llGracefulTimers.size());
assertEquals(STALE_TIME, llGracefulTimers.get(IPV4_KEY).intValue());
}
Aggregations