Search in sources :

Example 16 with Rib

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

the class BgpPeer method getBgpParameters.

private static List<BgpParameters> getBgpParameters(final AfiSafis afiSafis, final RIB rib, final BGPTableTypeRegistryConsumer tableTypeRegistry) {
    final List<BgpParameters> tlvs = new ArrayList<>();
    final List<OptionalCapabilities> caps = new ArrayList<>();
    caps.add(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(rib.getLocalAs()).build()).build()).build());
    caps.add(new OptionalCapabilitiesBuilder().setCParameters(BgpExtendedMessageUtil.EXTENDED_MESSAGE_CAPABILITY).build());
    caps.add(new OptionalCapabilitiesBuilder().setCParameters(MultiprotocolCapabilitiesUtil.RR_CAPABILITY).build());
    final List<AfiSafi> afiSafi = OpenConfigMappingUtil.getAfiSafiWithDefault(afiSafis, false);
    final List<AddressFamilies> addPathCapability = OpenConfigMappingUtil.toAddPathCapability(afiSafi, tableTypeRegistry);
    if (!addPathCapability.isEmpty()) {
        caps.add(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().addAugmentation(CParameters1.class, new CParameters1Builder().setAddPathCapability(new AddPathCapabilityBuilder().setAddressFamilies(addPathCapability).build()).build()).build()).build());
    }
    final List<BgpTableType> tableTypes = OpenConfigMappingUtil.toTableTypes(afiSafi, tableTypeRegistry);
    for (final BgpTableType tableType : tableTypes) {
        if (!rib.getLocalTables().contains(tableType)) {
            LOG.info("RIB instance does not list {} " + "in its local tables. Incoming data will be dropped.", tableType);
        }
        caps.add(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().addAugmentation(CParameters1.class, new CParameters1Builder().setMultiprotocolCapability(new MultiprotocolCapabilityBuilder(tableType).build()).build()).build()).build());
    }
    tlvs.add(new BgpParametersBuilder().setOptionalCapabilities(caps).build());
    return tlvs;
}
Also used : BgpTableType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.BgpTableType) OptionalCapabilitiesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.OptionalCapabilitiesBuilder) MultiprotocolCapabilityBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.MultiprotocolCapabilityBuilder) AfiSafi(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.AfiSafi) ArrayList(java.util.ArrayList) BgpParameters(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.BgpParameters) BgpParametersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.BgpParametersBuilder) OptionalCapabilities(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.OptionalCapabilities) As4BytesCapabilityBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.optional.capabilities.c.parameters.As4BytesCapabilityBuilder) CParametersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.optional.capabilities.CParametersBuilder) CParameters1Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.CParameters1Builder) AddressFamilies(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.add.path.capability.AddressFamilies) AddPathCapabilityBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.AddPathCapabilityBuilder)

Example 17 with Rib

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

the class BaseAbstractRouteEntry method fillAdjRibsOut.

@VisibleForTesting
@SuppressWarnings("unchecked")
private void fillAdjRibsOut(@Nullable final Attributes attributes, @Nullable final Route route, final Identifier routeKey, final PeerId fromPeerId, final RouteEntryDependenciesContainer routeEntryDep, final WriteTransaction tx) {
    /*
         * We need to keep track of routers and populate adj-ribs-out, too. If we do not, we need to
         * expose from which client a particular route was learned from in the local RIB, and have
         * the listener perform filtering.
         *
         * We walk the policy set in order to minimize the amount of work we do for multiple peers:
         * if we have two eBGP peers, for example, there is no reason why we should perform the translation
         * multiple times.
         */
    final TablesKey localTK = routeEntryDep.getLocalTablesKey();
    final BGPRibRoutingPolicy routingPolicies = routeEntryDep.getRoutingPolicies();
    final RIBSupport ribSupport = routeEntryDep.getRibSupport();
    for (final Peer toPeer : this.peerTracker.getPeers()) {
        if (!filterRoutes(fromPeerId, toPeer, localTK)) {
            continue;
        }
        Optional<Attributes> effAttr = Optional.empty();
        final Peer fromPeer = this.peerTracker.getPeer(fromPeerId);
        if (fromPeer != null && attributes != null) {
            final BGPRouteEntryExportParameters routeEntry = new BGPRouteEntryExportParametersImpl(fromPeer, toPeer);
            effAttr = routingPolicies.applyExportPolicies(routeEntry, attributes);
        }
        final InstanceIdentifier ribOutTarget = ribSupport.createRouteIdentifier(toPeer.getRibOutIId(localTK), routeKey);
        if (effAttr.isPresent() && route != null) {
            LOG.debug("Write route {} to peer AdjRibsOut {}", route, toPeer.getPeerId());
            tx.put(LogicalDatastoreType.OPERATIONAL, ribOutTarget, route);
            tx.put(LogicalDatastoreType.OPERATIONAL, ribOutTarget.child(Attributes.class), effAttr.get());
        } else {
            LOG.trace("Removing {} from transaction for peer {}", ribOutTarget, toPeer.getPeerId());
            tx.delete(LogicalDatastoreType.OPERATIONAL, ribOutTarget);
        }
    }
}
Also used : BGPRibRoutingPolicy(org.opendaylight.protocol.bgp.rib.spi.policy.BGPRibRoutingPolicy) TablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.TablesKey) RIBSupport(org.opendaylight.protocol.bgp.rib.spi.RIBSupport) Peer(org.opendaylight.protocol.bgp.rib.spi.Peer) Attributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) KeyedInstanceIdentifier(org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier) BGPRouteEntryExportParametersImpl(org.opendaylight.protocol.bgp.mode.impl.BGPRouteEntryExportParametersImpl) BGPRouteEntryExportParameters(org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryExportParameters) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 18 with Rib

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

the class BgpConfigurationManager method replay.

@SuppressWarnings("checkstyle:IllegalCatch")
public synchronized boolean replay() throws InterruptedException, TimeoutException, ExecutionException {
    boolean replaySucceded = true;
    boolean doRouteSync = false;
    String host = getConfigHost();
    int port = getConfigPort();
    LOG.error("connecting  to bgp host {} ", host);
    boolean res = bgpRouter.connect(host, port);
    if (!res) {
        LOG.error("Cannot connect to BGP config server at {} {}", host, port);
        return replaySucceded;
    }
    config = getConfig();
    if (config == null) {
        LOG.error("bgp config is empty nothing to push to bgp");
        return replaySucceded;
    }
    BgpRouter br = bgpRouter;
    AsId asId = config.getAsId();
    if (asId == null) {
        LOG.error("bgp as-id is null");
        return replaySucceded;
    }
    long asNum = asId.getLocalAs().toJava();
    IpAddress routerId = asId.getRouterId();
    String rid = routerId == null ? "" : routerId.stringValue();
    int stalepathTime = (int) getStalePathtime(bgpGrRestartTime, config.getAsId());
    boolean announceFbit = true;
    boolean replayDone = false;
    final int numberOfStartBgpRetries = 3;
    RetryOnException startBgpRetry = new RetryOnException(numberOfStartBgpRetries);
    do {
        try {
            LOG.debug("Replaying BGPConfig ");
            br.startBgp(asNum, rid, bgpKaTime, bgpHoldTime, stalepathTime, announceFbit);
            LOG.debug("Replay BGPConfig successful");
            replayDone = true;
            break;
        } catch (BgpRouterException bre) {
            if (bre.getErrorCode() == BgpRouterException.BGP_ERR_ACTIVE) {
                LOG.debug("Starting the routesync for exception", bre);
                startBgpRetry.errorOccured();
                if (!startBgpRetry.shouldRetry()) {
                    doRouteSync = true;
                    replayDone = true;
                }
            } else {
                LOG.error("Replay: startBgp() received exception error {} : ", bre.getErrorCode(), bre);
                startBgpRetry.errorOccured();
            }
        } catch (TApplicationException tae) {
            if (tae.getType() == BgpRouterException.BGP_ERR_ACTIVE) {
                LOG.debug("Starting the routesync for exception", tae);
                startBgpRetry.errorOccured();
                if (!startBgpRetry.shouldRetry()) {
                    doRouteSync = true;
                    replayDone = true;
                }
            } else if (tae.getType() == BgpRouterException.BGP_ERR_COMMON_FAILURE) {
                LOG.debug("Starting the routesync for AS-ID started exception", tae);
                startBgpRetry.errorOccured();
                if (!startBgpRetry.shouldRetry()) {
                    doRouteSync = true;
                    replayDone = true;
                }
            } else {
                LOG.error("Replay: startBgp() received exception type {}: ", tae.getType(), tae);
                startBgpRetry.errorOccured();
            }
        } catch (Exception e) {
            // not unusual. We may have restarted & BGP is already on
            LOG.error("Replay:startBgp() received exception: ", e);
            startBgpRetry.errorOccured();
        }
    } while (startBgpRetry.shouldRetry());
    replaySucceded = replayDone;
    startBgpCountersTask();
    startBgpAlarmsTask();
    /*
         * commenting this due to a bug with QBGP. Will uncomment once QBGP fix is done.
         * This wont have any functional impacts
         */
    // try {
    // br.delayEOR(delayEorSeconds);
    // } catch (TException | BgpRouterException e) {
    // LOG.error("Replay: delayEOR() number of seconds to wait for EOR from ODL:", e);
    // }
    BfdConfig bfdConfig = bgpUtil.getBfdConfig();
    if (bfdConfig != null) {
        if (bfdConfig.isBfdEnabled()) {
            LOG.debug("Replaying bfd config min-rx {} min-tx {} detect-mul {} mhop {}", bfdConfig.getMinRx(), bfdConfig.getMinTx(), bfdConfig.getDetectMult(), bfdConfig.isMultihop());
            try {
                br.addBfd(bfdConfig.getDetectMult().intValue(), bfdConfig.getMinRx().intValue(), bfdConfig.getMinTx().intValue(), bfdConfig.isMultihop());
            } catch (TApplicationException tae) {
                if (tae.getType() == BgpRouterException.BGP_ERR_PEER_EXISTS) {
                    LOG.debug("Replay:addBfd() received exception", tae);
                } else {
                    LOG.error("Replay:addBfd() received exception", tae);
                }
            } catch (TException | BgpRouterException e) {
                LOG.error("Replay:addBfd() received exception", e);
            }
        }
    }
    Map<NeighborsKey, Neighbors> keyNeighborsMap = config.getNeighborsContainer() == null ? null : config.getNeighborsContainer().getNeighbors();
    if (keyNeighborsMap != null) {
        LOG.error("configuring existing Neighbors present for replay total keyNeighborsMap {}", keyNeighborsMap.values().size());
        boolean neighborConfigReplayResult = replayNbrConfig(new ArrayList<Neighbors>(keyNeighborsMap.values()), br);
        if (neighborConfigReplayResult == false) {
            replaySucceded = false;
        }
    } else {
        LOG.error("no Neighbors present for replay config ");
    }
    Logging logging = config.getLogging();
    if (logging != null) {
        try {
            br.setLogging(logging.getFile(), logging.getLevel());
        } catch (TException | BgpRouterException e) {
            LOG.error("Replay:setLogging() received exception", e);
        }
    }
    GracefulRestart gracefulRestart = config.getGracefulRestart();
    bgpGrRestartTime = ((gracefulRestart != null) ? gracefulRestart.getStalepathTime().intValue() : bgpGrRestartTime);
    try {
        br.addGracefulRestart(bgpGrRestartTime);
    } catch (Exception e) {
        LOG.error("Replay:addGr() received exception: ", e);
    }
    Map<VrfsKey, Vrfs> keyVrfsMap = config.getVrfsContainer() == null ? null : config.getVrfsContainer().getVrfs();
    if (keyVrfsMap == null) {
        keyVrfsMap = new HashMap<VrfsKey, Vrfs>();
    }
    for (Vrfs vrf : keyVrfsMap.values()) {
        for (AddressFamiliesVrf adf : vrf.getAddressFamiliesVrf().values()) {
            try {
                br.addVrf(BgpUtil.getLayerType(adf), vrf.getRd(), vrf.getImportRts(), vrf.getExportRts(), adf.getAfi().toJava(), adf.getSafi().toJava());
            } catch (TException | BgpRouterException e) {
                LOG.error("Replay:addVrf() received exception", e);
            }
        }
    }
    Map<NetworksKey, Networks> keyNetworksMap = config.getNetworksContainer() == null ? null : config.getNetworksContainer().getNetworks();
    if (keyNetworksMap != null) {
        for (Networks net : keyNetworksMap.values()) {
            String rd = net.getRd();
            String pfxlen = net.getPrefixLen();
            String nh = net.getNexthop().getValue();
            Long label = net.getLabel().toJava();
            int lbl = label == null ? 0 : label.intValue();
            int l3vni = net.getL3vni() == null ? 0 : net.getL3vni().intValue();
            int l2vni = net.getL2vni() == null ? 0 : net.getL2vni().intValue();
            if (rd == null && lbl > 0) {
                // LU prefix is being deleted.
                rd = Integer.toString(lbl);
            }
            BgpControlPlaneType protocolType = net.getBgpControlPlaneType();
            int ethernetTag = net.getEthtag().intValue();
            String esi = net.getEsi();
            String macaddress = net.getMacaddress();
            EncapType encapType = net.getEncapType();
            String routerMac = net.getRoutermac();
            try {
                br.addPrefix(rd, pfxlen, nh, lbl, l3vni, l2vni, BgpUtil.convertToThriftProtocolType(protocolType), ethernetTag, esi, macaddress, BgpUtil.convertToThriftEncapType(encapType), routerMac);
            } catch (TException | BgpRouterException e) {
                LOG.error("Replay:addPfx() received exception", e);
            }
        }
    }
    Map<MultipathKey, Multipath> keyMultipathMap = config.getMultipathContainer() == null ? null : config.getMultipathContainer().getMultipath();
    if (keyMultipathMap != null) {
        for (Multipath multipath : keyMultipathMap.values()) {
            if (multipath != null) {
                af_afi afi = af_afi.findByValue(multipath.getAfi().intValue());
                af_safi safi = af_safi.findByValue(multipath.getSafi().intValue());
                try {
                    if (multipath.isMultipathEnabled()) {
                        br.enableMultipath(afi, safi);
                    } else {
                        br.disableMultipath(afi, safi);
                    }
                } catch (TException | BgpRouterException e) {
                    LOG.info("Replay:keyMultipathMap() received exception", e);
                }
            }
        }
    }
    Map<VrfMaxpathKey, VrfMaxpath> keyVrfMaxpathMap = config.getVrfMaxpathContainer() == null ? null : config.getVrfMaxpathContainer().getVrfMaxpath();
    if (keyVrfMaxpathMap != null) {
        for (VrfMaxpath vrfMaxpath : keyVrfMaxpathMap.values()) {
            try {
                br.multipaths(vrfMaxpath.getRd(), vrfMaxpath.getMaxpaths().toJava());
            } catch (TException | BgpRouterException e) {
                LOG.info("Replay:vrfMaxPath() received exception", e);
            }
        }
    }
    // send End of Rib Marker to Qthriftd.
    final int numberOfEORRetries = 3;
    RetryOnException eorRetry = new RetryOnException(numberOfEORRetries);
    do {
        try {
            br.sendEOR();
            LOG.debug("Replay sendEOR() successful");
            break;
        } catch (Exception e) {
            eorRetry.errorOccured();
            LOG.error("Replay:sedEOR() received exception:", e);
        }
    } while (eorRetry.shouldRetry());
    if (doRouteSync) {
        LOG.debug("starting route sync for Thrift BGP_ERR_COMMON_FAILURE exception " + "happened earlier");
        doRouteSync();
    }
    return replaySucceded;
}
Also used : TException(org.apache.thrift.TException) Vrfs(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.vrfscontainer.Vrfs) Networks(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.networkscontainer.Networks) VrfsKey(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.vrfscontainer.VrfsKey) org.opendaylight.netvirt.bgpmanager.thrift.gen.af_safi(org.opendaylight.netvirt.bgpmanager.thrift.gen.af_safi) AsId(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.AsId) BgpRouterException(org.opendaylight.netvirt.bgpmanager.thrift.client.BgpRouterException) BfdConfig(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebfd.rev190219.BfdConfig) BgpControlPlaneType(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.BgpControlPlaneType) EncapType(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.EncapType) org.opendaylight.netvirt.bgpmanager.thrift.gen.af_afi(org.opendaylight.netvirt.bgpmanager.thrift.gen.af_afi) Logging(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.Logging) MultipathKey(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.multipathcontainer.MultipathKey) VrfMaxpathKey(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.vrfmaxpathcontainer.VrfMaxpathKey) Neighbors(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighborscontainer.Neighbors) BgpRouter(org.opendaylight.netvirt.bgpmanager.thrift.client.BgpRouter) VrfMaxpath(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.vrfmaxpathcontainer.VrfMaxpath) InvocationTargetException(java.lang.reflect.InvocationTargetException) SocketException(java.net.SocketException) TException(org.apache.thrift.TException) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException) BgpRouterException(org.opendaylight.netvirt.bgpmanager.thrift.client.BgpRouterException) CandidateAlreadyRegisteredException(org.opendaylight.mdsal.eos.common.api.CandidateAlreadyRegisteredException) TApplicationException(org.apache.thrift.TApplicationException) TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) TApplicationException(org.apache.thrift.TApplicationException) Multipath(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.multipathcontainer.Multipath) NetworksKey(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.networkscontainer.NetworksKey) GracefulRestart(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.GracefulRestart) AddressFamiliesVrf(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.vrfscontainer.vrfs.AddressFamiliesVrf) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) NeighborsKey(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighborscontainer.NeighborsKey)

Example 19 with Rib

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib.Rib 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 20 with Rib

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

the class PCEPSessionNegotiator method startNegotiation.

@Override
@SuppressWarnings("checkstyle:IllegalCatch")
protected // similar to bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/AbstractBGPSessionNegotiator.java
void startNegotiation() throws ExecutionException {
    final Object lock = this;
    LOG.debug("Bootstrap negotiation for channel {} started", this.channel);
    /*
         * We have a chance to see if there's a client session already
         * registered for this client.
         */
    final byte[] clientAddress = ((InetSocketAddress) this.channel.remoteAddress()).getAddress().getAddress();
    final PCEPPeerRegistry sessionReg = this.negFactory.getSessionRegistry();
    synchronized (lock) {
        if (sessionReg.getSessionReference(clientAddress).isPresent()) {
            final byte[] serverAddress = ((InetSocketAddress) this.channel.localAddress()).getAddress().getAddress();
            if (COMPARATOR.compare(serverAddress, clientAddress) > 0) {
                final Optional<SessionReference> sessionRefMaybe = sessionReg.removeSessionReference(clientAddress);
                try {
                    if (sessionRefMaybe.isPresent()) {
                        sessionRefMaybe.get().close();
                    }
                } catch (final Exception e) {
                    LOG.error("Unexpected failure to close old session", e);
                }
            } else {
                negotiationFailed(new IllegalStateException("A conflicting session for address " + ((InetSocketAddress) this.channel.remoteAddress()).getAddress() + " found."));
                return;
            }
        }
        final Short sessionId = sessionReg.nextSession(clientAddress);
        final AbstractPCEPSessionNegotiator n = this.negFactory.createNegotiator(this.nfd, this.promise, this.channel, sessionId);
        sessionReg.putSessionReference(clientAddress, new SessionReference() {

            @Override
            public void close() throws ExecutionException {
                try {
                    sessionReg.releaseSession(clientAddress, sessionId);
                } finally {
                    PCEPSessionNegotiator.this.channel.close();
                }
            }

            @Override
            public Short getSessionId() {
                return sessionId;
            }
        });
        this.channel.closeFuture().addListener((ChannelFutureListener) future -> {
            synchronized (lock) {
                sessionReg.removeSessionReference(clientAddress);
            }
        });
        LOG.info("Replacing bootstrap negotiator for channel {}", this.channel);
        this.channel.pipeline().replace(this, "negotiator", n);
        n.startNegotiation();
    }
}
Also used : UnsignedBytes(com.google.common.primitives.UnsignedBytes) Logger(org.slf4j.Logger) Promise(io.netty.util.concurrent.Promise) LoggerFactory(org.slf4j.LoggerFactory) InetSocketAddress(java.net.InetSocketAddress) Channel(io.netty.channel.Channel) ExecutionException(java.util.concurrent.ExecutionException) PCEPSessionNegotiatorFactoryDependencies(org.opendaylight.protocol.pcep.PCEPSessionNegotiatorFactoryDependencies) SessionReference(org.opendaylight.protocol.pcep.impl.PCEPPeerRegistry.SessionReference) ChannelFutureListener(io.netty.channel.ChannelFutureListener) Message(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Message) Optional(java.util.Optional) Comparator(java.util.Comparator) InetSocketAddress(java.net.InetSocketAddress) SessionReference(org.opendaylight.protocol.pcep.impl.PCEPPeerRegistry.SessionReference) ExecutionException(java.util.concurrent.ExecutionException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

Test (org.junit.Test)16 Ipv4Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix)7 InetSocketAddress (java.net.InetSocketAddress)5 Before (org.junit.Before)5 Ipv6Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix)5 Update (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update)5 RibId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.RibId)5 ByteBuf (io.netty.buffer.ByteBuf)4 TablesKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey)4 ChannelFuture (io.netty.channel.ChannelFuture)3 ExecutionException (java.util.concurrent.ExecutionException)3 PathSelectionMode (org.opendaylight.protocol.bgp.mode.api.PathSelectionMode)3 BgpTableTypeImpl (org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl)3 PeerSpecificParserConstraint (org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint)3 BgpTableType (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.BgpTableType)3 ArrayList (java.util.ArrayList)2 BGPRouteEntryExportParametersImpl (org.opendaylight.protocol.bgp.mode.impl.BGPRouteEntryExportParametersImpl)2 NeighborBuilder (org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.NeighborBuilder)2 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)2 Ipv4Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)2