Search in sources :

Example 21 with Peer

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.peers.Peer in project bgpcep by opendaylight.

the class EffectiveRibInWriter method writeRoute.

private void writeRoute(final DOMDataTreeWriteTransaction tx, final RIBSupport<?, ?> ribSupport, final YangInstanceIdentifier routePath, final Optional<NormalizedNode> routeBefore, final NormalizedNode routeAfter, final boolean longLivedStale) {
    final TablesKey tablesKey = ribSupport.getTablesKey();
    CountersUtil.increment(this.prefixesReceived.get(tablesKey), tablesKey);
    // Lookup per-table attributes from RIBSupport
    final ContainerNode advertisedAttrs = (ContainerNode) NormalizedNodes.findNode(routeAfter, ribSupport.routeAttributesIdentifier()).orElse(null);
    final Attributes routeAttrs = ribSupport.attributeFromContainerNode(advertisedAttrs);
    final Optional<Attributes> optEffAtt;
    // considered as received with LLGR_STALE from peer which is not true.
    if (longLivedStale) {
        // LLGR procedures are in effect. If the route is tagged with NO_LLGR, it needs to be removed.
        final List<Communities> effCommunities = routeAttrs.getCommunities();
        if (effCommunities != null && effCommunities.contains(CommunityUtil.NO_LLGR)) {
            deleteRoute(tx, ribSupport, routePath, routeBefore.orElse(null));
            return;
        }
        optEffAtt = Optional.of(wrapLongLivedStale(routeAttrs));
    } else {
        optEffAtt = ribPolicies.applyImportPolicies(peerImportParameters, routeAttrs, verifyNotNull(tableTypeRegistry.getAfiSafiType(ribSupport.getTablesKey())));
    }
    if (!optEffAtt.isPresent()) {
        deleteRoute(tx, ribSupport, routePath, routeBefore.orElse(null));
        return;
    }
    handleRouteTarget(ModificationType.WRITE, ribSupport, routePath, routeAfter);
    tx.put(LogicalDatastoreType.OPERATIONAL, routePath, routeAfter);
    CountersUtil.increment(this.prefixesInstalled.get(tablesKey), tablesKey);
    final Attributes attToStore = optEffAtt.get();
    if (!attToStore.equals(routeAttrs)) {
        final YangInstanceIdentifier attPath = routePath.node(ribSupport.routeAttributesIdentifier());
        final ContainerNode finalAttribute = ribSupport.attributeToContainerNode(attPath, attToStore);
        tx.put(LogicalDatastoreType.OPERATIONAL, attPath, finalAttribute);
    }
}
Also used : TablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey) Communities(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.Communities) Attributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Example 22 with Peer

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.peers.Peer in project bgpcep by opendaylight.

the class AbstractAddPathTest method configurePeer.

static BGPPeer configurePeer(final BGPTableTypeRegistryConsumer tableRegistry, final Ipv4AddressNoZone peerAddress, final RIBImpl ribImpl, final BgpParameters bgpParameters, final PeerRole peerRole, final BGPPeerRegistry bgpPeerRegistry, final Set<TablesKey> afiSafiAdvertised, final Set<TablesKey> gracefulAfiSafiAdvertised, final Map<TablesKey, Integer> llGracefulTimersAdvertised, final BgpPeer peer) {
    final IpAddressNoZone ipAddress = new IpAddressNoZone(peerAddress);
    final BGPPeer bgpPeer = new BGPPeer(tableRegistry, new IpAddressNoZone(peerAddress), null, ribImpl, peerRole, null, null, null, afiSafiAdvertised, gracefulAfiSafiAdvertised, llGracefulTimersAdvertised, peer);
    final List<BgpParameters> tlvs = Lists.newArrayList(bgpParameters);
    bgpPeerRegistry.addPeer(ipAddress, bgpPeer, new BGPSessionPreferences(AS_NUMBER, HOLDTIMER, new BgpId(RIB_ID), AS_NUMBER, tlvs));
    bgpPeer.instantiateServiceInstance();
    return bgpPeer;
}
Also used : BGPSessionPreferences(org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences) BgpId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.BgpId) IpAddressNoZone(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone) BgpParameters(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.BgpParameters)

Example 23 with Peer

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.peers.Peer in project bgpcep by opendaylight.

the class OpenConfigMappingUtilTest method getRevisedErrorHandlingTest.

@Test
public void getRevisedErrorHandlingTest() {
    final NeighborBuilder neighbor = new NeighborBuilder().setNeighborAddress(NEIGHBOR_ADDRESS);
    final PeerGroupBuilder peerGroup = new PeerGroupBuilder().setPeerGroupName("foo");
    final org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.error.handling.ConfigBuilder errorHandlingConfig = new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.error.handling.ConfigBuilder();
    // error handling not set -> null
    assertNull(OpenConfigMappingUtil.getRevisedErrorHandling(PeerRole.Ibgp, peerGroup.build(), neighbor.build()));
    // error handling for peer group disabled, neighbor not set -> null
    peerGroup.setErrorHandling(new ErrorHandlingBuilder().setConfig(errorHandlingConfig.setTreatAsWithdraw(false).build()).build());
    assertNull(OpenConfigMappingUtil.getRevisedErrorHandling(PeerRole.Ibgp, peerGroup.build(), neighbor.build()));
    // error handling for peer group enabled, neighbor not set, Igp -> error handling for internal peer
    peerGroup.setErrorHandling(new ErrorHandlingBuilder().setConfig(errorHandlingConfig.setTreatAsWithdraw(true).build()).build());
    assertEquals(RevisedErrorHandlingSupportImpl.forInternalPeer(), OpenConfigMappingUtil.getRevisedErrorHandling(PeerRole.Ibgp, peerGroup.build(), neighbor.build()));
    // error handling for peer group enabled, neighbor disabled -> null
    neighbor.setErrorHandling(new ErrorHandlingBuilder().setConfig(errorHandlingConfig.setTreatAsWithdraw(false).build()).build());
    assertNull(OpenConfigMappingUtil.getRevisedErrorHandling(PeerRole.Ibgp, peerGroup.build(), neighbor.build()));
    // error handling for peer group enabled, neighbor enabled, Igb -> error handling for internal peer
    neighbor.setErrorHandling(new ErrorHandlingBuilder().setConfig(errorHandlingConfig.setTreatAsWithdraw(true).build()).build());
    assertEquals(RevisedErrorHandlingSupportImpl.forInternalPeer(), OpenConfigMappingUtil.getRevisedErrorHandling(PeerRole.Ibgp, peerGroup.build(), neighbor.build()));
    // error handling for peer group enabled, neighbor enabled, Egb -> error handling for external peer
    neighbor.setErrorHandling(new ErrorHandlingBuilder().setConfig(errorHandlingConfig.setTreatAsWithdraw(true).build()).build());
    assertEquals(RevisedErrorHandlingSupportImpl.forExternalPeer(), OpenConfigMappingUtil.getRevisedErrorHandling(PeerRole.Ebgp, peerGroup.build(), neighbor.build()));
}
Also used : PeerGroupBuilder(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.peer.group.PeerGroupBuilder) NeighborBuilder(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.NeighborBuilder) ErrorHandlingBuilder(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.ErrorHandlingBuilder) PeerGroupTransportConfigBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180329.network.instance.protocol.PeerGroupTransportConfigBuilder) NeighborPeerGroupConfigBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180329.network.instance.protocol.NeighborPeerGroupConfigBuilder) NeighborAddPathsConfigBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180329.network.instance.protocol.NeighborAddPathsConfigBuilder) ConfigBuilder(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.ConfigBuilder) GlobalAddPathsConfigBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180329.network.instance.protocol.GlobalAddPathsConfigBuilder) NeighborTransportConfigBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180329.network.instance.protocol.NeighborTransportConfigBuilder) Test(org.junit.Test)

Example 24 with Peer

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.peers.Peer in project bgpcep by opendaylight.

the class OpenConfigMappingUtilTest method getGracefulRestartTimerTest.

@Test
public void getGracefulRestartTimerTest() {
    final int neighborTimer = 5;
    final int peerGroupTimer = 10;
    Neighbor neighbor = new NeighborBuilder().setNeighborAddress(NEIGHBOR_ADDRESS).setGracefulRestart(new GracefulRestartBuilder().setConfig(createGracefulConfig(Uint16.valueOf(neighborTimer))).build()).build();
    PeerGroup peerGroup = new PeerGroupBuilder().setPeerGroupName("foo").setGracefulRestart(new GracefulRestartBuilder().setConfig(createGracefulConfig(Uint16.valueOf(peerGroupTimer))).build()).build();
    // both timers present, pick peer group one
    int timer = OpenConfigMappingUtil.getGracefulRestartTimer(neighbor, peerGroup, HOLDTIMER);
    assertEquals(peerGroupTimer, timer);
    // peer group missing graceful restart, use neighbor timer
    timer = OpenConfigMappingUtil.getGracefulRestartTimer(neighbor, EMPTY_PEERGROUP, HOLDTIMER);
    assertEquals(neighborTimer, timer);
    // graceful restart enabled but timer not set, use hold time
    peerGroup = new PeerGroupBuilder().setPeerGroupName("bar").setGracefulRestart(new GracefulRestartBuilder().setConfig(createGracefulConfig(null)).build()).build();
    timer = OpenConfigMappingUtil.getGracefulRestartTimer(EMPTY_NEIGHBOR, peerGroup, HOLDTIMER);
    assertEquals(HOLDTIMER, timer);
}
Also used : PeerGroupBuilder(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.peer.group.PeerGroupBuilder) Neighbor(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.Neighbor) PeerGroup(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.peer.group.PeerGroup) NeighborBuilder(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.NeighborBuilder) GracefulRestartBuilder(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.graceful.restart.GracefulRestartBuilder) Test(org.junit.Test)

Example 25 with Peer

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.peers.Peer in project bgpcep by opendaylight.

the class StrictBGPPeerRegistryTest method testDuplicatePeersLowerAs.

@Test
public void testDuplicatePeersLowerAs() throws Exception {
    final AsNumber as2 = new AsNumber(Uint32.valueOf(3));
    this.peerRegistry.addPeer(REMOTE_IP, this.peer1, this.mockPreferences);
    this.peerRegistry.getPeer(REMOTE_IP, FROM, TO, this.classicOpen);
    try {
        this.peerRegistry.getPeer(REMOTE_IP, FROM, TO, createOpen(TO, as2));
    } catch (final BGPDocumentedException e) {
        assertEquals(BGPError.CEASE, e.getError());
        return;
    }
    fail("Same peer cannot be connected twice");
}
Also used : BGPDocumentedException(org.opendaylight.protocol.bgp.parser.BGPDocumentedException) AsNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)29 ByteBuf (io.netty.buffer.ByteBuf)13 BGPDocumentedException (org.opendaylight.protocol.bgp.parser.BGPDocumentedException)11 IpAddressNoZone (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone)9 BGPSessionPreferences (org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences)8 Peer (org.opendaylight.protocol.bgp.rib.spi.Peer)8 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)7 ArrayList (java.util.ArrayList)6 AsNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber)6 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)6 BGPRouteEntryExportParametersImpl (org.opendaylight.protocol.bgp.mode.impl.BGPRouteEntryExportParametersImpl)5 RIBSupport (org.opendaylight.protocol.bgp.rib.spi.RIBSupport)5 BGPRouteEntryExportParameters (org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryExportParameters)5 BgpParameters (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.BgpParameters)5 PeerId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerId)5 CommitInfo (org.opendaylight.mdsal.common.api.CommitInfo)4 PeerSpecificParserConstraint (org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint)4 Ipv4AddressNoZone (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone)4 Ipv4Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix)4 PortStatusMessage (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage)4