Search in sources :

Example 1 with Uint24

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;
}
Also used : TablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.ll.graceful.restart.capability.TablesKey) Tables(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.ll.graceful.restart.capability.Tables) Uint24(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev171204.Uint24) ByteBuf(io.netty.buffer.ByteBuf)

Example 2 with Uint24

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)));
}
Also used : Ipv6AddressFamily(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.Ipv6AddressFamily) 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) Ipv4AddressFamily(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.Ipv4AddressFamily) LlGracefulRestartCapability(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.LlGracefulRestartCapability) CParameters(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.optional.capabilities.CParameters) Uint24(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev171204.Uint24) LlGracefulRestartCapabilityBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.LlGracefulRestartCapabilityBuilder) ByteBuf(io.netty.buffer.ByteBuf) TablesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.ll.graceful.restart.capability.TablesBuilder) Test(org.junit.Test)

Example 3 with Uint24

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;
}
Also used : TablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey) HashMap(java.util.HashMap) Config(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.afi.safi.graceful.restart.Config) Config1(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.ll.graceful.restart.rev181112.Config1) LlGracefulRestart(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.ll.graceful.restart.rev181112.afi.safi.ll.graceful.restart.LlGracefulRestart) GracefulRestart(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.afi.safi.GracefulRestart) Config2(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.ll.graceful.restart.rev181112.Config2) Uint24(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev171204.Uint24) LlGracefulRestart(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.ll.graceful.restart.rev181112.afi.safi.ll.graceful.restart.LlGracefulRestart)

Example 4 with Uint24

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));
}
Also used : SrCapabilities(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.node.state.SrCapabilities) SidCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.sid.label.index.sid.label.index.SidCaseBuilder) PrefixSidCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.binding.sub.tlvs.binding.sub.tlv.PrefixSidCaseBuilder) Uint24(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev171204.Uint24) ByteBuf(io.netty.buffer.ByteBuf) SrCapabilitiesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.node.state.SrCapabilitiesBuilder) Test(org.junit.Test)

Example 5 with Uint24

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());
}
Also used : Assert.assertNotNull(org.junit.Assert.assertNotNull) Config1Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.ll.graceful.restart.rev181112.Config1Builder) Collections(java.util.Collections) AfiSafi(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.AfiSafi) ArrayList(java.util.ArrayList) GracefulRestartBuilder(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.afi.safi.GracefulRestartBuilder) LlGracefulRestartBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.ll.graceful.restart.rev181112.afi.safi.ll.graceful.restart.LlGracefulRestartBuilder) AfiSafiBuilder(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.AfiSafiBuilder) ConfigBuilder(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.afi.safi.graceful.restart.ConfigBuilder) TablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey) LlGracefulRestartBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.ll.graceful.restart.rev181112.afi.safi.ll.graceful.restart.LlGracefulRestartBuilder) Mockito.doReturn(org.mockito.Mockito.doReturn) Uint24(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev171204.Uint24) IPV4UNICAST(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.IPV4UNICAST) Test(org.junit.Test)

Aggregations

Uint24 (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev171204.Uint24)8 Test (org.junit.Test)5 CParametersBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.optional.capabilities.CParametersBuilder)4 CParameters1Builder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.CParameters1Builder)4 LlGracefulRestartCapabilityBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.LlGracefulRestartCapabilityBuilder)4 TablesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.ll.graceful.restart.capability.TablesBuilder)4 ByteBuf (io.netty.buffer.ByteBuf)3 CParameters (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.optional.capabilities.CParameters)3 LlGracefulRestartCapability (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.LlGracefulRestartCapability)3 Ipv4AddressFamily (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.Ipv4AddressFamily)3 Ipv6AddressFamily (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.Ipv6AddressFamily)3 LlGracefulCapabilityHandler (org.opendaylight.protocol.bgp.parser.impl.message.open.LlGracefulCapabilityHandler)2 Tables (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.ll.graceful.restart.capability.Tables)2 TablesKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.ll.graceful.restart.capability.TablesKey)2 TablesKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Assert.assertNotNull (org.junit.Assert.assertNotNull)1 Mockito.doReturn (org.mockito.Mockito.doReturn)1