Search in sources :

Example 31 with BGP

use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.policy.types.rev151009.BGP in project bgpcep by opendaylight.

the class SrAttributeParserTest method testIpv6SrPrefix.

// https://tools.ietf.org/html/draft-gredler-idr-bgp-ls-segment-routing-ext-02#section-2.3.2
@Test
public void testIpv6SrPrefix() {
    final byte[] bytes = { 0, 0, 0 };
    final Ipv6SrPrefix prefix = new Ipv6SrPrefixBuilder().setAlgorithm(Algorithm.ShortestPathFirst).build();
    assertEquals(prefix, Ipv6SrPrefixAttributesParser.parseSrIpv6Prefix(Unpooled.wrappedBuffer(bytes)));
    final ByteBuf serializedPrefix = Unpooled.buffer();
    Ipv6SrPrefixAttributesParser.serializeIpv6SrPrefix(prefix, serializedPrefix);
    assertArrayEquals(bytes, ByteArray.readAllBytes(serializedPrefix));
}
Also used : Ipv6SrPrefixBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.prefix.state.Ipv6SrPrefixBuilder) Ipv6SrPrefix(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.prefix.state.Ipv6SrPrefix) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 32 with BGP

use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.policy.types.rev151009.BGP in project bgpcep by opendaylight.

the class MatchBgpNeighborSetTest method testMatchFromBgpNeighborInvert.

@Test
public void testMatchFromBgpNeighborInvert() {
    Statement statement = this.basicStatements.stream().filter(st -> st.getName().equals("reject-from-neighbor-invert-test")).findFirst().get();
    RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(new AttributesBuilder().build());
    doReturn(new PeerId("bgp://42.42.42.42")).when(this.exportParameters).getFromPeerId();
    RouteAttributeContainer result = this.statementRegistry.applyExportStatement(this.baseAttributes, this.exportParameters, attributeContainer, statement);
    assertNull(result.getAttributes());
    doReturn(new PeerId("bgp://127.0.0.1")).when(this.exportParameters).getFromPeerId();
    result = this.statementRegistry.applyExportStatement(this.baseAttributes, this.exportParameters, attributeContainer, statement);
    assertNotNull(result.getAttributes());
}
Also used : Statement(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.routing.policy.policy.definitions.policy.definition.statements.Statement) RouteAttributeContainer(org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer) AttributesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.AttributesBuilder) PeerId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerId) Test(org.junit.Test)

Example 33 with BGP

use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.policy.types.rev151009.BGP in project bgpcep by opendaylight.

the class MatchBgpNeighborSetTest method testMatchToBgpNeighborInvert.

@Test
public void testMatchToBgpNeighborInvert() {
    Statement statement = this.basicStatements.stream().filter(st -> st.getName().equals("reject-to-neighbor-invert-test")).findFirst().get();
    RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(new AttributesBuilder().build());
    doReturn(new PeerId("bgp://127.0.0.2")).when(this.exportParameters).getFromPeerId();
    doReturn(new PeerId("bgp://42.42.42.42")).when(this.exportParameters).getToPeerId();
    RouteAttributeContainer result = this.statementRegistry.applyExportStatement(this.baseAttributes, this.exportParameters, attributeContainer, statement);
    assertNull(result.getAttributes());
    doReturn(new PeerId("bgp://127.0.0.1")).when(this.exportParameters).getToPeerId();
    result = this.statementRegistry.applyExportStatement(this.baseAttributes, this.exportParameters, attributeContainer, statement);
    assertNotNull(result.getAttributes());
}
Also used : Statement(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.routing.policy.policy.definitions.policy.definition.statements.Statement) RouteAttributeContainer(org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer) AttributesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.AttributesBuilder) PeerId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerId) Test(org.junit.Test)

Example 34 with BGP

use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.policy.types.rev151009.BGP in project bgpcep by opendaylight.

the class BGPOperationalStateUtils method readGlobalFromDataStore.

private static Bgp readGlobalFromDataStore(final DataBroker dataBroker, final String ribId) {
    final InstanceIdentifier<Bgp> bgpIID = PROTOCOLS_IID.child(Protocol.class, new ProtocolKey(BGP.class, ribId)).augmentation(NetworkInstanceProtocol.class).child(Bgp.class);
    final ReadOnlyTransaction rot = dataBroker.newReadOnlyTransaction();
    try {
        return rot.read(LogicalDatastoreType.OPERATIONAL, bgpIID).get().orNull();
    } catch (final InterruptedException | ExecutionException e) {
        LOG.warn("Failed to read rib {}", ribId, e);
    }
    return null;
}
Also used : ProtocolKey(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.protocols.ProtocolKey) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) Bgp(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.Bgp) BGP(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.policy.types.rev151009.BGP) NetworkInstanceProtocol(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.NetworkInstanceProtocol) ExecutionException(java.util.concurrent.ExecutionException)

Example 35 with BGP

use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.policy.types.rev151009.BGP in project bgpcep by opendaylight.

the class BGPNotificationMessageParser method parseMessageBody.

/**
 * Parses BGP Notification message to bytes.
 *
 * @param body ByteBuf to be parsed
 * @param messageLength the length of the message
 * @return {@link Notify} which represents BGP notification message
 * @throws BGPDocumentedException if parsing goes wrong
 */
@Override
public Notify parseMessageBody(final ByteBuf body, final int messageLength) throws BGPDocumentedException {
    Preconditions.checkArgument(body != null, "Buffer cannot be null.");
    if (body.readableBytes() < ERROR_SIZE) {
        throw BGPDocumentedException.badMessageLength("Notification message too small.", messageLength);
    }
    final int errorCode = body.readUnsignedByte();
    final int errorSubcode = body.readUnsignedByte();
    final NotifyBuilder builder = new NotifyBuilder().setErrorCode((short) errorCode).setErrorSubcode((short) errorSubcode);
    if (body.isReadable()) {
        builder.setData(ByteArray.readAllBytes(body));
    }
    LOG.debug("BGP Notification message was parsed: err = {}, data = {}.", BGPError.forValue(errorCode, errorSubcode), Arrays.toString(builder.getData()));
    return builder.build();
}
Also used : NotifyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.NotifyBuilder)

Aggregations

BigInteger (java.math.BigInteger)18 Test (org.junit.Test)17 ByteBuf (io.netty.buffer.ByteBuf)16 ArrayList (java.util.ArrayList)16 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)16 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)11 VrfEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry)10 ExecutionException (java.util.concurrent.ExecutionException)9 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)9 BGPDocumentedException (org.opendaylight.protocol.bgp.parser.BGPDocumentedException)9 Bgp (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp)7 BgpParameters (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.BgpParameters)7 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)7 List (java.util.List)6 Ipv4Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)6 AttributesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.AttributesBuilder)6 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)5 InstructionGotoTable (org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable)5 Neighbors (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.Neighbors)5 Collections (java.util.Collections)4