Search in sources :

Example 41 with Object

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object in project bgpcep by opendaylight.

the class BGPSynchronization method updReceived.

/**
 * For each received Update message, the upd sync variable needs to be updated to true, for particular AFI/SAFI
 * combination. Currently we only assume Unicast SAFI. From the Update message we have to extract the AFI. Each
 * Update message can contain BGP Object with one type of AFI. If the object is BGP Link, BGP Node or a BGPPrefix
 * the AFI is Linkstate. In case of BGPRoute, the AFI depends on the IP Address of the prefix.
 *
 * @param msg received Update message
 */
public void updReceived(final Update msg) {
    TablesKey type = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
    boolean isEOR = false;
    if (msg.getNlri() == null && msg.getWithdrawnRoutes() == null) {
        if (msg.getAttributes() != null) {
            if (msg.getAttributes().getAugmentation(Attributes1.class) != null) {
                final Attributes1 pa = msg.getAttributes().getAugmentation(Attributes1.class);
                if (pa.getMpReachNlri() != null) {
                    type = new TablesKey(pa.getMpReachNlri().getAfi(), pa.getMpReachNlri().getSafi());
                }
            } else if (msg.getAttributes().getAugmentation(Attributes2.class) != null) {
                final Attributes2 pa = msg.getAttributes().getAugmentation(Attributes2.class);
                if (pa.getMpUnreachNlri() != null) {
                    type = new TablesKey(pa.getMpUnreachNlri().getAfi(), pa.getMpUnreachNlri().getSafi());
                }
                if (pa.getMpUnreachNlri().getWithdrawnRoutes() == null) {
                    // EOR message contains only MPUnreach attribute and no NLRI
                    isEOR = true;
                }
            }
        } else {
            // true for empty Update Message
            isEOR = true;
        }
    }
    syncType(type, isEOR);
}
Also used : TablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.TablesKey) Attributes2(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.Attributes2) Attributes1(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.Attributes1)

Example 42 with Object

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object in project bgpcep by opendaylight.

the class AbstractPCEPSessionTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    this.receivedMsgs = new ArrayList<>();
    doAnswer(invocation -> {
        final Object[] args = invocation.getArguments();
        AbstractPCEPSessionTest.this.receivedMsgs.add((Notification) args[0]);
        return this.channelFuture;
    }).when(this.clientListener).writeAndFlush(any(Notification.class));
    doReturn(null).when(this.channelFuture).addListener(Mockito.any());
    doReturn("TestingChannel").when(this.clientListener).toString();
    doReturn(this.pipeline).when(this.clientListener).pipeline();
    doReturn(this.pipeline).when(this.pipeline).replace(any(ChannelHandler.class), any(String.class), any(ChannelHandler.class));
    doReturn(this.eventLoop).when(this.clientListener).eventLoop();
    doNothing().when(this.statsRegistry).bind(any(), any());
    doNothing().when(this.statsRegistry).unbind(any());
    doReturn(null).when(this.eventLoop).schedule(any(Runnable.class), any(long.class), any(TimeUnit.class));
    doReturn(true).when(this.clientListener).isActive();
    final InetSocketAddress ra = new InetSocketAddress(this.testAddress, 4189);
    doReturn(ra).when(this.clientListener).remoteAddress();
    final InetSocketAddress la = new InetSocketAddress(this.testAddress, InetSocketAddressUtil.getRandomPort());
    doReturn(la).when(this.clientListener).localAddress();
    doReturn(mock(ChannelFuture.class)).when(this.clientListener).close();
    doReturn(getDataBroker()).when(this.topologyDependencies).getDataBroker();
    doReturn(this.statsRegistry).when(this.topologyDependencies).getStateRegistry();
    @SuppressWarnings("unchecked") final T listenerFactory = (T) ((Class) ((ParameterizedType) this.getClass().getGenericSuperclass()).getActualTypeArguments()[0]).newInstance();
    doReturn(new IpAddress(new Ipv4Address(this.testAddress))).when(this.sessionConfig).getListenAddress();
    doReturn(new PortNumber(4189)).when(this.sessionConfig).getListenPort();
    doReturn(RPC_TIMEOUT).when(this.sessionConfig).getRpcTimeout();
    doReturn(TEST_TOPOLOGY_ID).when(this.topology).getTopologyId();
    doReturn(Collections.emptyList()).when(this.topology).getNode();
    final PCEPTopologyConfiguration configDep = new PCEPTopologyConfiguration(this.sessionConfig, this.topology);
    this.manager = new ServerSessionManager(this.topologyDependencies, listenerFactory, configDep);
    startSessionManager();
    this.neg = new DefaultPCEPSessionNegotiator(this.promise, this.clientListener, this.manager.getSessionListener(), (short) 1, 5, this.localPrefs);
    this.topologyRpcs = new TopologyRPCs(this.manager);
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) PCEPTopologyConfiguration(org.opendaylight.bgpcep.pcep.topology.provider.config.PCEPTopologyConfiguration) InetSocketAddress(java.net.InetSocketAddress) ChannelHandler(io.netty.channel.ChannelHandler) Notification(org.opendaylight.yangtools.yang.binding.Notification) TimeUnit(java.util.concurrent.TimeUnit) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) DefaultPCEPSessionNegotiator(org.opendaylight.protocol.pcep.impl.DefaultPCEPSessionNegotiator) PortNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address) Before(org.junit.Before)

Example 43 with Object

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object in project bgpcep by opendaylight.

the class PCEPObjectParserTest method testLspaObject.

@Test
public void testLspaObject() throws IOException, PCEPDeserializerException {
    final Stateful07LspaObjectParser parser = new Stateful07LspaObjectParser(this.tlvRegistry, this.viTlvRegistry);
    final LspaBuilder builder = new LspaBuilder();
    final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspaObject3RandVals.bin"));
    final SymbolicPathName tlv = new SymbolicPathNameBuilder().setPathName(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.SymbolicPathName(new byte[] { (byte) 0x4d, (byte) 0x65, (byte) 0x64, (byte) 0x20, (byte) 0x74, (byte) 0x65, (byte) 0x73, (byte) 0x74, (byte) 0x20, (byte) 0x6f, (byte) 0x66, (byte) 0x20, (byte) 0x73, (byte) 0x79, (byte) 0x6d, (byte) 0x62, (byte) 0x6f, (byte) 0x6c, (byte) 0x69, (byte) 0x63, (byte) 0x20, (byte) 0x6e, (byte) 0x61, (byte) 0x6d, (byte) 0x65 })).build();
    builder.setIgnore(false);
    builder.setProcessingRule(false);
    builder.setExcludeAny(new AttributeFilter(0x20A1FEE3L));
    builder.setIncludeAny(new AttributeFilter(0x1A025CC7L));
    builder.setIncludeAll(new AttributeFilter(0x2BB66532L));
    builder.setHoldPriority((short) 0x02);
    builder.setSetupPriority((short) 0x03);
    builder.setLocalProtectionDesired(true);
    builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.lspa.TlvsBuilder().addAugmentation(Tlvs2.class, new Tlvs2Builder().setSymbolicPathName(tlv).build()).build());
    // Tlvs container does not contain toString
    final Object o = parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4));
    assertEquals(tlv, ((Lspa) o).getTlvs().getAugmentation(Tlvs2.class).getSymbolicPathName());
    // assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), ByteArray.cutBytes(result,
    // 4)));
    final ByteBuf buf = Unpooled.buffer();
    parser.serializeObject(builder.build(), buf);
    assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
}
Also used : LspaBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.LspaBuilder) ObjectHeaderImpl(org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl) SymbolicPathNameBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.symbolic.path.name.tlv.SymbolicPathNameBuilder) Tlvs2Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.Tlvs2Builder) ByteBuf(io.netty.buffer.ByteBuf) Stateful07LspaObjectParser(org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07LspaObjectParser) AttributeFilter(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.AttributeFilter) SymbolicPathName(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.symbolic.path.name.tlv.SymbolicPathName) Test(org.junit.Test)

Example 44 with Object

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object in project bgpcep by opendaylight.

the class PCEPValidatorTest method testUnexpectedRroObjectInPcUpdMsg.

@Test
public void testUnexpectedRroObjectInPcUpdMsg() throws PCEPDeserializerException {
    final byte[] badUpdateMsg = { (byte) 0x20, (byte) 0x0b, (byte) 0x00, (byte) 0x50, /* SRP, LSP and ERO objects */
    (byte) 0x21, (byte) 0x12, (byte) 0x00, (byte) 0x0c, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x20, (byte) 0x10, (byte) 0x00, (byte) 0x08, (byte) 0x00, (byte) 0x00, (byte) 0x10, (byte) 0x09, (byte) 0x07, (byte) 0x10, (byte) 0x00, (byte) 0x14, (byte) 0x01, (byte) 0x08, (byte) 0x05, (byte) 0x05, (byte) 0x05, (byte) 0x03, (byte) 0x18, (byte) 0x00, (byte) 0x01, (byte) 0x08, (byte) 0x08, (byte) 0x08, (byte) 0x08, (byte) 0x04, (byte) 0x18, (byte) 0x00, /* RRO object */
    (byte) 0x08, (byte) 0x10, (byte) 0x00, (byte) 0x24, (byte) 0x01, (byte) 0x08, (byte) 0x0a, (byte) 0x00, (byte) 0x00, (byte) 0x83, (byte) 0x20, (byte) 0x20, (byte) 0x03, (byte) 0x08, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x08, (byte) 0x0a, (byte) 0x00, (byte) 0x09, (byte) 0xde, (byte) 0x20, (byte) 0x00, (byte) 0x03, (byte) 0x08, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 };
    try (CrabbeInitiatedActivator a = new CrabbeInitiatedActivator()) {
        a.start(this.ctx);
        final Stateful07PCUpdateRequestMessageParser parser = new Stateful07PCUpdateRequestMessageParser(this.ctx.getObjectHandlerRegistry());
        final PcerrMessageBuilder errMsgBuilder = new PcerrMessageBuilder();
        errMsgBuilder.setErrors(Lists.newArrayList(new ErrorsBuilder().setErrorObject(new ErrorObjectBuilder().setType((short) 6).setValue((short) 10).build()).build()));
        final PcerrBuilder builder = new PcerrBuilder();
        builder.setPcerrMessage(errMsgBuilder.build());
        final ByteBuf buf = Unpooled.wrappedBuffer(badUpdateMsg);
        final List<Message> errors = Lists.newArrayList();
        parser.parseMessage(buf.slice(4, buf.readableBytes() - 4), errors);
        assertFalse(errors.isEmpty());
        assertEquals(builder.build(), errors.get(0));
    }
}
Also used : PcerrBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcerrBuilder) Message(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message) Stateful07PCUpdateRequestMessageParser(org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07PCUpdateRequestMessageParser) ErrorsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.ErrorsBuilder) ByteBuf(io.netty.buffer.ByteBuf) CrabbeInitiatedActivator(org.opendaylight.protocol.pcep.ietf.initiated00.CrabbeInitiatedActivator) PcerrMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.PcerrMessageBuilder) ErrorObjectBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.ErrorObjectBuilder) Test(org.junit.Test)

Example 45 with Object

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object in project bgpcep by opendaylight.

the class PCEPObjectParserTest method testEmptyEroObject.

@Test
public void testEmptyEroObject() throws PCEPDeserializerException {
    final Object object = this.ctx.getObjectHandlerRegistry().parseObject(PCEPExplicitRouteObjectParser.CLASS, PCEPExplicitRouteObjectParser.TYPE, new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
    assertNotNull(object);
    assertTrue(object instanceof Ero);
    final Ero eroObject = (Ero) object;
    assertTrue(eroObject.getSubobject().isEmpty());
    final ByteBuf buffer = Unpooled.buffer();
    this.ctx.getObjectHandlerRegistry().serializeObject(eroObject, buffer);
    final byte[] expected = { 0x07, 0x13, 0x00, 0x04 };
    assertArrayEquals(expected, ByteArray.getAllBytes(buffer));
}
Also used : Ero(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Ero) ObjectHeaderImpl(org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl) VendorInformationObject(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.objects.VendorInformationObject) UnknownObject(org.opendaylight.protocol.pcep.spi.UnknownObject) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)72 Test (org.junit.Test)60 ArrayList (java.util.ArrayList)46 Eid (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid)29 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)28 Attributes (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes)25 Object (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object)23 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)18 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)17 PCEPDeserializerException (org.opendaylight.protocol.pcep.spi.PCEPDeserializerException)16 VendorInformationObject (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.objects.VendorInformationObject)15 BigInteger (java.math.BigInteger)14 Preconditions (com.google.common.base.Preconditions)13 HashMap (java.util.HashMap)13 ObjectHeaderImpl (org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl)13 List (java.util.List)12 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)10 UnknownObject (org.opendaylight.protocol.pcep.spi.UnknownObject)10 BitArray (org.opendaylight.protocol.util.BitArray)9 Flowspec (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.Flowspec)9