Search in sources :

Example 11 with Esi

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.esi.Esi 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 12 with Esi

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.esi.Esi in project bgpcep by opendaylight.

the class EthADRParser method parseEvpn.

@Override
public EvpnChoice parseEvpn(final ByteBuf buffer) {
    Preconditions.checkArgument(buffer.readableBytes() == CONTENT_LENGTH, "Wrong length of array of bytes. Passed: %s ;", buffer);
    final Esi esi = SimpleEsiTypeRegistry.getInstance().parseEsi(buffer.readSlice(ESI_SIZE));
    final EthernetTagId eti = new EthernetTagIdBuilder().setVlanId(ByteBufUtils.readUint32(buffer)).build();
    final MplsLabel label = mplsLabelForByteBuf(buffer);
    final EthernetADRouteBuilder builder = new EthernetADRouteBuilder().setEsi(esi).setEthernetTagId(eti).setMplsLabel(label);
    return new EthernetADRouteCaseBuilder().setEthernetADRoute(builder.build()).build();
}
Also used : EthernetTagIdBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.ethernet.tag.id.EthernetTagIdBuilder) MplsLabel(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.MplsLabel) NlriModelUtil.extractMplsLabel(org.opendaylight.protocol.bgp.evpn.impl.nlri.NlriModelUtil.extractMplsLabel) MplsLabelUtil.byteBufForMplsLabel(org.opendaylight.protocol.util.MplsLabelUtil.byteBufForMplsLabel) EthernetADRouteCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.evpn.evpn.choice.EthernetADRouteCaseBuilder) Esi(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.esi.Esi) EthernetTagId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.ethernet.tag.id.EthernetTagId) EthernetADRouteBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.ethernet.a.d.route.EthernetADRouteBuilder)

Example 13 with Esi

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.esi.Esi in project bgpcep by opendaylight.

the class LanParser method serializeBody.

@Override
public ByteBuf serializeBody(final Esi esi, final ByteBuf body) {
    checkArgument(esi instanceof LanAutoGeneratedCase, "Unknown esi instance. Passed %s. Needed LanAutoGeneratedCase.", esi);
    final LanAutoGenerated lan = ((LanAutoGeneratedCase) esi).getLanAutoGenerated();
    body.writeBytes(IetfYangUtil.INSTANCE.macAddressBytes(lan.getRootBridgeMacAddress()));
    ByteBufUtils.writeOrZero(body, lan.getRootBridgePriority());
    return body.writeByte(0);
}
Also used : LanAutoGeneratedCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.esi.esi.LanAutoGeneratedCase) LanAutoGenerated(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.esi.esi.lan.auto.generated._case.LanAutoGenerated)

Example 14 with Esi

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.esi.Esi in project bgpcep by opendaylight.

the class RouterIdParser method serializeBody.

@Override
public ByteBuf serializeBody(final Esi esi, final ByteBuf body) {
    checkArgument(esi instanceof RouterIdGeneratedCase, "Unknown esi instance. Passed %s. Needed RouterIdGeneratedCase.", esi);
    final RouterIdGenerated routerID = ((RouterIdGeneratedCase) esi).getRouterIdGenerated();
    Ipv4Util.writeIpv4Address(routerID.getRouterId(), body);
    ByteBufUtils.writeOrZero(body, routerID.getLocalDiscriminator());
    return body.writeByte(0);
}
Also used : RouterIdGenerated(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.esi.esi.router.id.generated._case.RouterIdGenerated) RouterIdGeneratedCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.esi.esi.RouterIdGeneratedCase)

Example 15 with Esi

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.esi.Esi in project bgpcep by opendaylight.

the class EthSegRParser method parseEvpn.

@Override
public EvpnChoice parseEvpn(final ByteBuf buffer) {
    checkArgument(buffer.readableBytes() == CONTENT_LENGTH || buffer.readableBytes() == CONTENT_LENGTH2, "Wrong length of array of bytes. Passed: %s ;", buffer);
    final Esi esi = SimpleEsiTypeRegistry.getInstance().parseEsi(buffer.readSlice(ESI_SIZE));
    final IpAddressNoZone ip = IpAddressUtil.addressForByteBuf(buffer);
    final EsRouteBuilder builder = new EsRouteBuilder().setEsi(esi).setOrigRouteIp(ip);
    return new EsRouteCaseBuilder().setEsRoute(builder.build()).build();
}
Also used : EsRouteBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.es.route.EsRouteBuilder) Esi(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.esi.Esi) IpAddressNoZone(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone) EsRouteCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.evpn.evpn.choice.EsRouteCaseBuilder)

Aggregations

Esi (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.esi.Esi)10 ByteBuf (io.netty.buffer.ByteBuf)7 Test (org.junit.Test)6 NlriModelUtil.extractMplsLabel (org.opendaylight.protocol.bgp.evpn.impl.nlri.NlriModelUtil.extractMplsLabel)3 MplsLabelUtil.byteBufForMplsLabel (org.opendaylight.protocol.util.MplsLabelUtil.byteBufForMplsLabel)3 MplsLabel (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.MplsLabel)3 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)3 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)3 IpAddressNoZone (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone)2 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 SocketException (java.net.SocketException)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 TApplicationException (org.apache.thrift.TApplicationException)1 TException (org.apache.thrift.TException)1 TransactionCommitFailedException (org.opendaylight.mdsal.common.api.TransactionCommitFailedException)1 CandidateAlreadyRegisteredException (org.opendaylight.mdsal.eos.common.api.CandidateAlreadyRegisteredException)1 BgpRouter (org.opendaylight.netvirt.bgpmanager.thrift.client.BgpRouter)1 BgpRouterException (org.opendaylight.netvirt.bgpmanager.thrift.client.BgpRouterException)1