Search in sources :

Example 91 with Received

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.network.instances.network.instance.protocols.protocol.bgp.neighbors.neighbor.state.messages.Received in project netvirt by opendaylight.

the class BgpConfigurationManager method replay.

@SuppressWarnings("checkstyle:IllegalCatch")
public synchronized boolean replay() throws InterruptedException, TimeoutException, ExecutionException {
    boolean replaySucceded = true;
    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, config != null ? "; Configuration Replay aborted" : "");
        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();
    IpAddress routerId = asId.getRouterId();
    String rid = routerId == null ? "" : new String(routerId.getValue());
    int stalepathTime = (int) getStalePathtime(RESTART_DEFAULT_GR, 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, 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()) {
                    LOG.debug("starting route sync for BgpRouter exception");
                    doRouteSync();
                }
            } 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()) {
                    LOG.debug("starting route sync for Thrift BGP_ERR_ACTIVE exception");
                    doRouteSync();
                }
            } 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()) {
                    LOG.debug("starting route sync for Thrift BGP_ERR_COMMON_FAILURE exception");
                    doRouteSync();
                }
            } 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);
    // }
    List<Neighbors> neighbors = config.getNeighbors();
    if (neighbors != null) {
        LOG.error("configuring existing Neighbors present for replay total neighbors {}", neighbors.size());
        boolean neighborConfigReplayResult = replayNbrConfig(neighbors, 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();
    if (gracefulRestart != null) {
        try {
            br.addGracefulRestart(gracefulRestart.getStalepathTime().intValue());
        } catch (TException | BgpRouterException e) {
            LOG.error("Replay:addGr() received exception", e);
        }
    }
    List<Vrfs> vrfs = config.getVrfs();
    if (vrfs == null) {
        vrfs = new ArrayList<>();
    }
    for (Vrfs vrf : vrfs) {
        for (AddressFamiliesVrf adf : vrf.getAddressFamiliesVrf()) {
            try {
                br.addVrf(BgpUtil.getLayerType(adf), vrf.getRd(), vrf.getImportRts(), vrf.getExportRts());
            } catch (TException | BgpRouterException e) {
                LOG.error("Replay:addVrf() received exception", e);
            }
        }
    }
    List<Networks> ln = config.getNetworks();
    if (ln != null) {
        for (Networks net : ln) {
            String rd = net.getRd();
            String pfxlen = net.getPrefixLen();
            String nh = net.getNexthop().getValue();
            Long label = net.getLabel();
            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);
            }
        }
    }
    List<Multipath> multipaths = config.getMultipath();
    if (multipaths != null) {
        for (Multipath multipath : multipaths) {
            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:multipaths() received exception", e);
                }
            }
        }
    }
    List<VrfMaxpath> vrfMaxpaths = config.getVrfMaxpath();
    if (vrfMaxpaths != null) {
        for (VrfMaxpath vrfMaxpath : vrfMaxpaths) {
            try {
                br.multipaths(vrfMaxpath.getRd(), vrfMaxpath.getMaxpaths());
            } catch (TException | BgpRouterException e) {
                LOG.info("Replay:vrfMaxPath() received exception", e);
            }
        }
    }
    // send End of Rib Marker to Qthriftd.
    final int numberOfEORRetries = 3;
    replayDone = false;
    RetryOnException eorRetry = new RetryOnException(numberOfEORRetries);
    do {
        try {
            br.sendEOR();
            LOG.debug("Replay sendEOR {} successful");
            replayDone = true;
            break;
        } catch (Exception e) {
            eorRetry.errorOccured();
            LOG.error("Replay:sedEOR() received exception:", e);
        }
    } while (eorRetry.shouldRetry());
    return replaySucceded && replayDone;
}
Also used : TException(org.apache.thrift.TException) Vrfs(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.Vrfs) Networks(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.Networks) 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) 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) Neighbors(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.Neighbors) BgpRouter(org.opendaylight.netvirt.bgpmanager.thrift.client.BgpRouter) VrfMaxpath(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.VrfMaxpath) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SocketException(java.net.SocketException) TException(org.apache.thrift.TException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) 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) TApplicationException(org.apache.thrift.TApplicationException) Multipath(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.Multipath) 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.vrfs.AddressFamiliesVrf) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)

Example 92 with Received

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.network.instances.network.instance.protocols.protocol.bgp.neighbors.neighbor.state.messages.Received in project netvirt by opendaylight.

the class VpnToDpnListener method programVpnScfFlowsOnDpn.

private void programVpnScfFlowsOnDpn(BigInteger dpnId, String vpnName, String rd, int addOrRemove) {
    String addedOrRemovedTxt = addOrRemove == NwConstants.ADD_FLOW ? " added " : " removed";
    LOG.debug("DpnToVpn {} event received: dpn={}  vpn={}  rd={}", addedOrRemovedTxt, dpnId, vpnName, rd);
    if (dpnId == null) {
        LOG.warn("Dpn to Vpn {} event received, but no DPN specified in event", addedOrRemovedTxt);
        return;
    }
    if (vpnName == null) {
        LOG.warn("Dpn to Vpn {} event received, but no VPN specified in event", addedOrRemovedTxt);
        return;
    }
    if (rd == null) {
        LOG.warn("Dpn to Vpn {} event received, but no RD specified in event", addedOrRemovedTxt);
        return;
    }
    try {
        Optional<VpnToPseudoPortData> optVpnToPseudoPortInfo = VpnServiceChainUtils.getVpnPseudoPortData(broker, rd);
        if (!optVpnToPseudoPortInfo.isPresent()) {
            LOG.debug("Dpn to Vpn {} event received: Could not find VpnPseudoLportTag for VPN name={}  rd={}", addedOrRemovedTxt, vpnName, rd);
            return;
        }
        VpnToPseudoPortData vpnToPseudoPortInfo = optVpnToPseudoPortInfo.get();
        // Vpn2Scf flows (LFIB + LportDispatcher)
        // TODO: Should we filter out by bgp origin
        List<VrfEntry> allVpnVrfEntries = VpnServiceChainUtils.getAllVrfEntries(broker, rd);
        vpnScHandler.programVpnToScfPipelineOnDpn(dpnId, allVpnVrfEntries, vpnToPseudoPortInfo.getScfTableId(), vpnToPseudoPortInfo.getScfTag(), vpnToPseudoPortInfo.getVpnLportTag().intValue(), addOrRemove);
        // Scf2Vpn flow (LportDispatcher)
        long vpnId = addOrRemove == NwConstants.ADD_FLOW ? VpnServiceChainUtils.getVpnId(broker, vpnName) : CloudServiceChainConstants.INVALID_VPN_TAG;
        VpnServiceChainUtils.programLPortDispatcherFlowForScfToVpn(mdsalMgr, vpnId, dpnId, vpnToPseudoPortInfo.getVpnLportTag().intValue(), addOrRemove);
    } catch (ReadFailedException e) {
        LOG.error("Error retrieving the VPN to pseudo-port data for {}", rd, e);
    }
}
Also used : VrfEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) VpnToPseudoPortData(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.cloud.servicechain.state.rev160711.vpn.to.pseudo.port.list.VpnToPseudoPortData)

Example 93 with Received

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.network.instances.network.instance.protocols.protocol.bgp.neighbors.neighbor.state.messages.Received in project netvirt by opendaylight.

the class AclInterfaceListener method update.

@Override
public void update(InstanceIdentifier<Interface> key, Interface portBefore, Interface portAfter) {
    if (portBefore.getAugmentation(ParentRefs.class) == null && portAfter.getAugmentation(ParentRefs.class) != null) {
        LOG.trace("Ignoring event for update in ParentRefs for {} ", portAfter.getName());
        return;
    }
    LOG.trace("Received AclInterface update event, portBefore={}, portAfter={}", portBefore, portAfter);
    InterfaceAcl aclInPortAfter = portAfter.getAugmentation(InterfaceAcl.class);
    InterfaceAcl aclInPortBefore = portBefore.getAugmentation(InterfaceAcl.class);
    String interfaceId = portAfter.getName();
    org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface interfaceState = AclServiceUtils.getInterfaceStateFromOperDS(dataBroker, interfaceId);
    AclInterface aclInterfaceBefore = aclInterfaceCache.get(interfaceId);
    if (aclInterfaceBefore == null || isPortSecurityEnabledNow(aclInPortBefore, aclInPortAfter)) {
        // Updating cache now as it might have not updated when
        // port-security-enable=false
        aclInterfaceBefore = addOrUpdateAclInterfaceCache(interfaceId, aclInPortBefore, true, interfaceState);
    }
    if (aclInPortAfter != null && aclInPortAfter.isPortSecurityEnabled() || aclInPortBefore != null && aclInPortBefore.isPortSecurityEnabled()) {
        boolean isSgChanged = isSecurityGroupsChanged(aclInPortBefore.getSecurityGroups(), aclInPortAfter.getSecurityGroups());
        AclInterface aclInterfaceAfter = addOrUpdateAclInterfaceCache(interfaceId, aclInPortAfter, isSgChanged, interfaceState);
        if (aclClusterUtil.isEntityOwner()) {
            // Handle bind/unbind service irrespective of interface state (up/down)
            boolean isPortSecurityEnable = aclInterfaceAfter.isPortSecurityEnabled();
            boolean isPortSecurityEnableBefore = aclInterfaceBefore.isPortSecurityEnabled();
            // if port security enable is changed and is disabled, unbind ACL service
            if (isPortSecurityEnableBefore != isPortSecurityEnable && !isPortSecurityEnable) {
                LOG.debug("Notify unbind ACL service for interface={}, isPortSecurityEnable={}", interfaceId, isPortSecurityEnable);
                aclServiceManager.notify(aclInterfaceAfter, null, Action.UNBIND);
            }
            if (interfaceState != null && interfaceState.getOperStatus().equals(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus.Up)) {
                // if port security enable is changed and is enabled, bind ACL service
                if (isPortSecurityEnableBefore != isPortSecurityEnable && isPortSecurityEnable) {
                    LOG.debug("Notify bind ACL service for interface={}, isPortSecurityEnable={}", interfaceId, isPortSecurityEnable);
                    aclServiceManager.notify(aclInterfaceAfter, null, Action.BIND);
                }
                LOG.debug("On update event, notify ACL service manager to update ACL for interface: {}", interfaceId);
                // handle add for AclPortsLookup before processing update
                try {
                    Futures.allAsList(aclServiceUtils.addAclPortsLookupForInterfaceUpdate(aclInterfaceBefore, aclInterfaceAfter)).get();
                } catch (InterruptedException | ExecutionException e) {
                    LOG.error("Error adding ACL ports for interface update", e);
                }
                aclServiceManager.notify(aclInterfaceAfter, aclInterfaceBefore, AclServiceManager.Action.UPDATE);
                // handle delete for AclPortsLookup after processing update
                try {
                    Futures.allAsList(aclServiceUtils.deleteAclPortsLookupForInterfaceUpdate(aclInterfaceBefore, aclInterfaceAfter)).get();
                } catch (InterruptedException | ExecutionException e) {
                    LOG.error("Error deleting ACL ports for interface update", e);
                }
            }
        }
        updateCacheWithAclChange(aclInterfaceBefore, aclInterfaceAfter);
    }
}
Also used : AclInterface(org.opendaylight.netvirt.aclservice.api.utils.AclInterface) InterfaceAcl(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.InterfaceAcl) ExecutionException(java.util.concurrent.ExecutionException)

Example 94 with Received

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.network.instances.network.instance.protocols.protocol.bgp.neighbors.neighbor.state.messages.Received in project netvirt by opendaylight.

the class AclInterfaceListener method add.

@Override
public void add(InstanceIdentifier<Interface> key, Interface port) {
    LOG.trace("Received AclInterface add event, port={}", port);
    InterfaceAcl aclInPort = port.getAugmentation(InterfaceAcl.class);
    if (aclInPort != null && aclInPort.isPortSecurityEnabled()) {
        String interfaceId = port.getName();
        AclInterface aclInterface = addOrUpdateAclInterfaceCache(interfaceId, aclInPort);
        // if interface state event comes first followed by interface config event.
        if (aclInterface.getDpId() != null && aclInterface.getElanId() != null && aclClusterUtil.isEntityOwner()) {
            LOG.debug("On add event, notify ACL bind/add for interface: {}", interfaceId);
            aclServiceManager.notify(aclInterface, null, Action.BIND);
            aclServiceManager.notify(aclInterface, null, Action.ADD);
        }
    }
}
Also used : AclInterface(org.opendaylight.netvirt.aclservice.api.utils.AclInterface) InterfaceAcl(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.InterfaceAcl)

Example 95 with Received

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.network.instances.network.instance.protocols.protocol.bgp.neighbors.neighbor.state.messages.Received in project netvirt by opendaylight.

the class AclNodeListener method add.

@Override
protected void add(InstanceIdentifier<FlowCapableNode> key, FlowCapableNode dataObjectModification) {
    NodeKey nodeKey = key.firstKeyOf(Node.class);
    BigInteger dpId = MDSALUtil.getDpnIdFromNodeName(nodeKey.getId());
    LOG.info("Received ACL node [{}] add event", dpId);
    if (securityGroupMode != null && securityGroupMode != SecurityGroupMode.Stateful) {
        LOG.error("Invalid security group mode ({}) obtained from AclserviceConfig. dpId={}", securityGroupMode, dpId);
        return;
    }
    jobCoordinator.enqueueJob(String.valueOf(dpId), () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
        new AclNodeDefaultFlowsTxBuilder(dpId, mdsalManager, config, tx).build();
        LOG.info("Adding default ACL flows for dpId={}", dpId);
    })), AclConstants.JOB_MAX_RETRIES);
    LOG.trace("FlowCapableNode (dpid: {}) add event is processed.", dpId);
}
Also used : BigInteger(java.math.BigInteger) AclNodeDefaultFlowsTxBuilder(org.opendaylight.netvirt.aclservice.utils.AclNodeDefaultFlowsTxBuilder) NodeKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey)

Aggregations

BigInteger (java.math.BigInteger)26 ArrayList (java.util.ArrayList)20 ExecutionException (java.util.concurrent.ExecutionException)16 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)13 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)13 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)10 List (java.util.List)10 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)10 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)9 UnknownHostException (java.net.UnknownHostException)8 VpnInterface (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface)8 Network (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network)8 Optional (com.google.common.base.Optional)7 Test (org.junit.Test)7 PacketException (org.opendaylight.openflowplugin.libraries.liblldp.PacketException)7 Collections (java.util.Collections)6 TunnelTypeVxlan (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeVxlan)6 FutureCallback (com.google.common.util.concurrent.FutureCallback)5 Action (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action)5 NodeConnectorRef (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef)5