Search in sources :

Example 6 with RibId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.RibId in project bgpcep by opendaylight.

the class SynchronizationAndExceptionTest method testUseCase1.

@Test
public void testUseCase1() {
    final Map<TablesKey, PathSelectionMode> pathTables = ImmutableMap.of(TABLES_KEY, BasePathSelectionModeFactory.createBestPathSelectionStrategy());
    final RIBImpl ribImpl = new RIBImpl(this.tableRegistry, new RibId(RIB_ID), AS_NUMBER, new BgpId(RIB_ID), this.ribExtension, this.serverDispatcher, this.codecsRegistry, this.domBroker, this.policies, ImmutableList.of(this.ipv4tt), pathTables);
    ribImpl.instantiateServiceInstance();
    final BGPPeer bgpPeer = AbstractAddPathTest.configurePeer(this.tableRegistry, neighbor.getIpv4AddressNoZone(), ribImpl, null, PeerRole.Ibgp, this.serverRegistry, AFI_SAFIS_ADVERTIZED, Collections.emptySet());
    bgpPeer.instantiateServiceInstance();
    final BGPSessionImpl bgpSession = new BGPSessionImpl(bgpPeer, this.speakerListener, this.classicOpen, this.classicOpen.getHoldTimer().toJava(), null);
    bgpSession.setChannelExtMsgCoder(this.classicOpen);
    bgpPeer.onSessionUp(bgpSession);
    final Nlri n1 = new NlriBuilder().setPrefix(new Ipv4Prefix("8.0.1.0/28")).build();
    final Nlri n2 = new NlriBuilder().setPrefix(new Ipv4Prefix("127.0.0.1/32")).build();
    final Nlri n3 = new NlriBuilder().setPrefix(new Ipv4Prefix("2.2.2.2/24")).build();
    final List<Nlri> nlris = Lists.newArrayList(n1, n2, n3);
    final UpdateBuilder wrongMessage = new UpdateBuilder();
    wrongMessage.setNlri(nlris);
    final Origin origin = new OriginBuilder().setValue(BgpOrigin.Igp).build();
    final AsPath asPath = new AsPathBuilder().setSegments(Collections.emptyList()).build();
    final CNextHop nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(new Ipv4AddressNoZone("127.0.0.1")).build()).build();
    final AttributesBuilder ab = new AttributesBuilder();
    wrongMessage.setAttributes(ab.setOrigin(origin).setAsPath(asPath).setCNextHop(nextHop).build());
    final UpdateBuilder correct = new UpdateBuilder(wrongMessage.build());
    correct.setAttributes(ab.setLocalPref(new LocalPrefBuilder().setPref(Uint32.valueOf(100)).build()).build());
    bgpSession.handleMessage(correct.build());
    verify(this.tx, times(2)).merge(eq(LogicalDatastoreType.OPERATIONAL), any(YangInstanceIdentifier.class), any(NormalizedNode.class));
    bgpSession.handleMessage(new UpdateBuilder().build());
    verify(this.tx, times(3)).merge(eq(LogicalDatastoreType.OPERATIONAL), any(YangInstanceIdentifier.class), any(NormalizedNode.class));
    verify(this.tx).merge(eq(LogicalDatastoreType.OPERATIONAL), eq(TABLE_PATH), eq(ImmutableNodes.leafNode(UPTODATE_NID, Boolean.TRUE)));
    verify(this.tx, times(0)).delete(eq(LogicalDatastoreType.OPERATIONAL), eq(PEER_PATH));
}
Also used : Origin(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.Origin) BgpOrigin(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.BgpOrigin) LocalPrefBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.LocalPrefBuilder) Ipv4AddressNoZone(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone) OriginBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.OriginBuilder) UpdateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.UpdateBuilder) RibId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.RibId) AsPathBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.AsPathBuilder) Ipv4NextHopCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.Ipv4NextHopCaseBuilder) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Ipv4Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix) TablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey) CNextHop(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.CNextHop) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Nlri(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.update.message.Nlri) AsPath(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.AsPath) Ipv4NextHopBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.ipv4.next.hop._case.Ipv4NextHopBuilder) BgpId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.BgpId) PathSelectionMode(org.opendaylight.protocol.bgp.mode.api.PathSelectionMode) NlriBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.update.message.NlriBuilder) AttributesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder) Test(org.junit.Test)

Example 7 with RibId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.RibId in project bgpcep by opendaylight.

the class StateProviderImpl method storeOperationalState.

private synchronized void storeOperationalState(final BGPRibState bgpStateConsumer, final List<BGPPeerState> peerStats, final String ribId, final WriteTransaction wtx) {
    final Global global = GlobalUtil.buildGlobal(bgpStateConsumer, this.bgpTableTypeRegistry);
    final PeerGroups peerGroups = PeerGroupUtil.buildPeerGroups(peerStats);
    final Neighbors neighbors = NeighborUtil.buildNeighbors(peerStats, this.bgpTableTypeRegistry);
    InstanceIdentifier<Bgp> bgpIID = this.instanceIdentifiersCache.get(ribId);
    if (bgpIID == null) {
        final ProtocolKey protocolKey = new ProtocolKey(BGP.class, bgpStateConsumer.getInstanceIdentifier().getKey().getId().getValue());
        final KeyedInstanceIdentifier<Protocol, ProtocolKey> protocolIId = this.networkInstanceIId.child(Protocols.class).child(Protocol.class, protocolKey);
        bgpIID = protocolIId.augmentation(NetworkInstanceProtocol.class).child(Bgp.class);
        this.instanceIdentifiersCache.put(ribId, bgpIID);
    }
    final Bgp bgp = new BgpBuilder().setGlobal(global).setNeighbors(neighbors).setPeerGroups(peerGroups).build();
    wtx.put(LogicalDatastoreType.OPERATIONAL, bgpIID, bgp, WriteTransaction.CREATE_MISSING_PARENTS);
}
Also used : Protocols(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.Protocols) PeerGroups(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.PeerGroups) ProtocolKey(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.protocols.ProtocolKey) BgpBuilder(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.BgpBuilder) Neighbors(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.Neighbors) Bgp(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.Bgp) NetworkInstanceProtocol(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.NetworkInstanceProtocol) Protocol(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.protocols.Protocol) Global(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.Global)

Example 8 with RibId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.RibId in project bgpcep by opendaylight.

the class GlobalStateCliUtils method displayRibOperationalState.

static void displayRibOperationalState(@NonNull final String ribId, @NonNull final Global global, @NonNull final PrintStream stream) {
    final State globalState = global.getState();
    final ShellTable table = new ShellTable();
    table.column("Attribute").alignLeft();
    table.column("Value").alignLeft();
    addHeader(table, "RIB state");
    table.addRow().addContent("Router Id", ribId);
    table.addRow().addContent("As", globalState.getAs());
    table.addRow().addContent("Total Paths", globalState.getTotalPaths());
    table.addRow().addContent("Total Prefixes", globalState.getTotalPrefixes());
    global.getAfiSafis().nonnullAfiSafi().values().forEach(afiSafi -> displayAfiSafi(afiSafi, table));
    table.print(stream);
}
Also used : ShellTable(org.apache.karaf.shell.support.table.ShellTable) State(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.global.base.State)

Example 9 with RibId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.RibId in project bgpcep by opendaylight.

the class RibImpl method createRib.

private synchronized RIBImpl createRib(final Global global, final BGPTableTypeRegistryConsumer tableTypeRegistry) {
    afiSafi = getAfiSafiWithDefault(global.getAfiSafis(), true).values();
    final Config globalConfig = global.getConfig();
    asNumber = globalConfig.getAs();
    routerId = IetfInetUtil.INSTANCE.ipv4AddressNoZoneFor(globalConfig.getRouterId());
    clusterId = getGlobalClusterIdentifier(globalConfig);
    final Map<TablesKey, PathSelectionMode> pathSelectionModes = OpenConfigMappingUtil.toPathSelectionMode(afiSafi, tableTypeRegistry).entrySet().stream().collect(Collectors.toMap(entry -> new TablesKey(entry.getKey().getAfi(), entry.getKey().getSafi()), Map.Entry::getValue));
    final BGPRibRoutingPolicy ribPolicy = policyProvider.buildBGPRibPolicy(asNumber.getValue().toJava(), routerId, clusterId, RoutingPolicyUtil.getApplyPolicy(global.getApplyPolicy()));
    return new RIBImpl(tableTypeRegistry, ribId, asNumber, new BgpId(routerId), extensionProvider, dispatcher, codecsRegistry, domBroker, ribPolicy, toTableTypes(afiSafi, tableTypeRegistry), pathSelectionModes);
}
Also used : OpenConfigMappingUtil.getGlobalClusterIdentifier(org.opendaylight.protocol.bgp.rib.impl.config.OpenConfigMappingUtil.getGlobalClusterIdentifier) LoggerFactory(org.slf4j.LoggerFactory) BGPDispatcher(org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher) BGPStateProviderRegistry(org.opendaylight.protocol.bgp.rib.spi.state.BGPStateProviderRegistry) IetfInetUtil(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IetfInetUtil) Ipv4AddressNoZone(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone) Map(java.util.Map) AfiSafi(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.AfiSafi) RIBImpl(org.opendaylight.protocol.bgp.rib.impl.RIBImpl) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) OpenConfigMappingUtil.toTableTypes(org.opendaylight.protocol.bgp.rib.impl.config.OpenConfigMappingUtil.toTableTypes) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address) Collection(java.util.Collection) Set(java.util.Set) TablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey) PeerId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerId) Collectors(java.util.stream.Collectors) Preconditions.checkState(com.google.common.base.Preconditions.checkState) DOMDataBroker(org.opendaylight.mdsal.dom.api.DOMDataBroker) GuardedBy(org.checkerframework.checker.lock.qual.GuardedBy) DOMTransactionChain(org.opendaylight.mdsal.dom.api.DOMTransactionChain) BGPRibRoutingPolicyFactory(org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.BGPRibRoutingPolicyFactory) Registration(org.opendaylight.yangtools.concepts.Registration) BgpTableType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.BgpTableType) RIB(org.opendaylight.protocol.bgp.rib.impl.spi.RIB) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) DOMTransactionChainListener(org.opendaylight.mdsal.dom.api.DOMTransactionChainListener) Config(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.global.base.Config) ClusterIdentifier(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.ClusterIdentifier) BGPRibRoutingPolicy(org.opendaylight.protocol.bgp.rib.spi.policy.BGPRibRoutingPolicy) BgpId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.BgpId) Objects.requireNonNull(java.util.Objects.requireNonNull) RIBSupportContextRegistry(org.opendaylight.protocol.bgp.rib.impl.spi.RIBSupportContextRegistry) CodecsRegistry(org.opendaylight.protocol.bgp.rib.impl.spi.CodecsRegistry) BGPPeerTracker(org.opendaylight.protocol.bgp.rib.spi.BGPPeerTracker) Global(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.Global) Rib(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib.Rib) Logger(org.slf4j.Logger) BGPRibState(org.opendaylight.protocol.bgp.rib.spi.state.BGPRibState) PathSelectionMode(org.opendaylight.protocol.bgp.mode.api.PathSelectionMode) RibKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib.RibKey) DOMDataTreeChangeService(org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService) Futures(com.google.common.util.concurrent.Futures) OpenConfigMappingUtil.getAfiSafiWithDefault(org.opendaylight.protocol.bgp.rib.impl.config.OpenConfigMappingUtil.getAfiSafiWithDefault) AsNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber) KeyedInstanceIdentifier(org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier) BGPTableTypeRegistryConsumer(org.opendaylight.protocol.bgp.openconfig.spi.BGPTableTypeRegistryConsumer) RibId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.RibId) RIBExtensionConsumerContext(org.opendaylight.protocol.bgp.rib.spi.RIBExtensionConsumerContext) BGPRibStateProvider(org.opendaylight.protocol.bgp.rib.spi.state.BGPRibStateProvider) FluentFuture(com.google.common.util.concurrent.FluentFuture) BGPRibRoutingPolicy(org.opendaylight.protocol.bgp.rib.spi.policy.BGPRibRoutingPolicy) TablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey) BgpId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.BgpId) Config(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.global.base.Config) PathSelectionMode(org.opendaylight.protocol.bgp.mode.api.PathSelectionMode) Map(java.util.Map) RIBImpl(org.opendaylight.protocol.bgp.rib.impl.RIBImpl)

Example 10 with RibId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.RibId in project bgpcep by opendaylight.

the class RibImpl method start.

synchronized void start(final Global global, final String instanceName, final BGPTableTypeRegistryConsumer tableTypeRegistry) {
    checkState(ribImpl == null, "Previous instance %s was not closed.", this);
    LOG.info("Starting BGP instance {}", instanceName);
    ribId = new RibId(instanceName);
    ribImpl = createRib(global, tableTypeRegistry);
    stateProviderRegistration = stateProviderRegistry.register(this);
}
Also used : RibId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.RibId)

Aggregations

RibId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.RibId)11 PathSelectionMode (org.opendaylight.protocol.bgp.mode.api.PathSelectionMode)8 TablesKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey)6 Before (org.junit.Before)5 ChannelFuture (io.netty.channel.ChannelFuture)4 InetSocketAddress (java.net.InetSocketAddress)4 Test (org.junit.Test)4 BgpTableTypeImpl (org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl)4 Global (org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.Global)4 BgpTableType (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.BgpTableType)4 BgpId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.BgpId)4 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)4 Futures (com.google.common.util.concurrent.Futures)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 AllPathSelection (org.opendaylight.protocol.bgp.mode.impl.add.all.paths.AllPathSelection)2 BGPRibRoutingPolicyFactory (org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.BGPRibRoutingPolicyFactory)2