Search in sources :

Example 16 with Server

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.config.rev200120.server.config.Server 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 17 with Server

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.config.rev200120.server.config.Server in project netvirt by opendaylight.

the class EgressAclServiceImpl method egressAclDhcpAllowClientTraffic.

/**
 * Add rule to ensure only DHCP server traffic from the specified mac is allowed.
 *
 * @param flowEntries the flow entries
 * @param port the Acl Interface port
 * @param allowedAddresses the allowed addresses
 * @param lportTag the lport tag
 * @param addOrRemove whether to add or remove the flow
 */
private void egressAclDhcpAllowClientTraffic(List<FlowEntity> flowEntries, AclInterface port, List<AllowedAddressPairs> allowedAddresses, int lportTag, int addOrRemove) {
    Uint64 dpId = Uint64.valueOf(port.getDpId());
    List<InstructionInfo> instructions = getDispatcherTableResubmitInstructions();
    for (AllowedAddressPairs aap : allowedAddresses) {
        if (!AclServiceUtils.isIPv4Address(aap)) {
            continue;
        }
        List<MatchInfoBase> matches = new ArrayList<>();
        matches.addAll(AclServiceUtils.buildDhcpMatches(AclConstants.DHCP_CLIENT_PORT_IPV4, AclConstants.DHCP_SERVER_PORT_IPV4, lportTag, serviceMode));
        matches.add(new MatchEthernetSource(aap.getMacAddress()));
        String flowName = "Egress_DHCP_Client_v4" + dpId + "_" + lportTag + "_" + aap.getMacAddress().getValue() + "_Permit_";
        addFlowEntryToList(flowEntries, dpId, getAclAntiSpoofingTable(), flowName, AclConstants.PROTO_DHCP_CLIENT_TRAFFIC_MATCH_PRIORITY, 0, 0, AclConstants.COOKIE_ACL_BASE, matches, instructions, addOrRemove);
    }
}
Also used : InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) MatchEthernetSource(org.opendaylight.genius.mdsalutil.matches.MatchEthernetSource) ArrayList(java.util.ArrayList) AllowedAddressPairs(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.AllowedAddressPairs) MatchInfoBase(org.opendaylight.genius.mdsalutil.MatchInfoBase) Uint64(org.opendaylight.yangtools.yang.common.Uint64)

Example 18 with Server

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.config.rev200120.server.config.Server in project netvirt by opendaylight.

the class Cache method doExecute.

@SuppressWarnings({ "resource", "checkstyle:RegexpSinglelineJava" })
@Override
protected Object doExecute() {
    boolean listVrfs = false;
    boolean listNets = false;
    PrintStream ps = System.out;
    if (action != null) {
        return usage();
    }
    PrintStream fileStream = null;
    try {
        if (ofile != null) {
            try {
                fileStream = new PrintStream(ofile);
                ps = fileStream;
            } catch (FileNotFoundException e) {
                System.out.println("error: cannot create file " + ofile + "; exception: " + e);
                return null;
            }
        }
        if (list != null) {
            for (String item : list) {
                switch(item) {
                    case "vrfs":
                        listVrfs = true;
                        break;
                    case "networks":
                        listNets = true;
                        break;
                    default:
                        System.out.println("error: unknown value for " + LST + ": " + item);
                        if (fileStream != null) {
                            fileStream.close();
                        }
                        return null;
                }
            }
        }
        // we'd normally read this directly from 'config' but
        // legacy behaviour forces to check for a connection
        // that's initiated by default at startup without
        // writing to config.
        String configHost = bgpManager.getConfigHost();
        int configPort = bgpManager.getConfigPort();
        ps.printf("%nConfiguration Server%n\t%s  %s%n\t%s  %d%n", HTSTR, configHost, PTSTR, configPort);
        Bgp config = bgpManager.getConfig();
        if (config == null) {
            if (fileStream != null) {
                fileStream.close();
            }
            return null;
        }
        AsId asId = config.getAsId();
        if (asId != null) {
            Long asNum = asId.getLocalAs().longValue();
            IpAddress routerId = asId.getRouterId();
            Long spt = asId.getStalepathTime().toJava();
            Boolean afb = asId.isAnnounceFbit();
            String rid = routerId == null ? "<n/a>" : routerId.stringValue();
            // F-bit is always set to ON (hardcoded), in SDN even though the controller is down
            // forwarding state shall be retained.
            String bit = "ON";
            GracefulRestart gracefulRestart = config.getGracefulRestart();
            if (gracefulRestart != null) {
                spt = gracefulRestart.getStalepathTime().toJava();
            }
            ps.printf("%nBGP Router%n");
            ps.printf("\t%-15s  %s%n\t%-15s  %s%n\t%-15s  %s%n\t%-15s  %s%n", ASSTR, asNum.toString(), RISTR, rid, SPSTR, spt == null || spt == 0 ? "default" : spt.toString(), FBSTR, bit);
        }
        Logging logging = config.getLogging();
        if (logging != null) {
            ps.printf("\t%-15s  %s%n\t%-15s  %s%n", LFSTR, logging.getFile(), LLSTR, logging.getLevel());
        }
        Map<NeighborsKey, Neighbors> keyNeighborsMap = (config.getNeighborsContainer() == null) ? null : config.getNeighborsContainer().getNeighbors();
        if (keyNeighborsMap != null) {
            ps.printf("%nNeighbors%n");
            for (Neighbors nbr : keyNeighborsMap.values()) {
                ps.printf("\t%s%n\t\t%-16s  %d%n", nbr.getAddress().getValue(), ASSTR, nbr.getRemoteAs());
                EbgpMultihop en = nbr.getEbgpMultihop();
                if (en != null) {
                    ps.printf("\t\t%-16s  %d%n", EBSTR, en.getNhops().intValue());
                }
                UpdateSource us = nbr.getUpdateSource();
                if (us != null) {
                    ps.printf("\t\t%-16s  %s%n", USSTR, us.getSourceIp().getValue());
                }
                ps.printf("\t\t%-16s  IPv4-Labeled-VPN", AFSTR);
                Map<AddressFamiliesKey, AddressFamilies> keyAddressFamiliesMap = nbr.getAddressFamilies();
                if (keyAddressFamiliesMap != null) {
                    for (AddressFamilies af : keyAddressFamiliesMap.values()) {
                        // Should not print "unknown" in vpnv4 case
                        if (!(af.getSafi().intValue() == 5 && af.getAfi().intValue() == 1)) {
                            if (af.getSafi().intValue() == 4 && af.getAfi().intValue() == 1) {
                                ps.printf(" %s", "IPv4-Labeled-Unicast");
                            } else if (af.getSafi().intValue() == 5 && af.getAfi().intValue() == 2) {
                                ps.printf(" %s", "IPv6-Labeled-VPN");
                            } else if (af.getSafi().intValue() == 6) {
                                ps.printf(" %s", "Ethernet-VPN");
                            } else {
                                ps.printf(" %s", "Unknown");
                            }
                        }
                    }
                }
                ps.printf("%n");
            }
        }
        if (listVrfs) {
            Map<VrfsKey, Vrfs> keyVrfsMap = (config.getVrfsContainer() == null) ? null : config.getVrfsContainer().getVrfs();
            if (keyVrfsMap != null) {
                ps.printf("%nVRFs%n");
                for (Vrfs vrf : keyVrfsMap.values()) {
                    ps.printf("\t%s%n", vrf.getRd());
                    ps.printf("\t\t%s  ", IRSTR);
                    for (String rt : vrf.getImportRts()) {
                        ps.printf("%s ", rt);
                    }
                    ps.printf("%n\t\t%s  ", ERSTR);
                    for (String rt : vrf.getExportRts()) {
                        ps.printf("%s ", rt);
                    }
                    for (AddressFamiliesVrf adf : vrf.getAddressFamiliesVrf().values()) {
                        ps.printf("%n\t\tafi %d safi %d", adf.getAfi(), adf.getSafi());
                    }
                    ps.printf("%n");
                }
            }
        }
        if (listNets) {
            Map<NetworksKey, Networks> keyNetworksMap = (config.getNetworksContainer() == null) ? null : config.getNetworksContainer().getNetworks();
            if (keyNetworksMap != null) {
                ps.printf("%nNetworks%n");
                for (Networks net : keyNetworksMap.values()) {
                    String rd = net.getRd();
                    String pfxlen = net.getPrefixLen();
                    String nh = net.getNexthop().getValue();
                    int label = net.getLabel().intValue();
                    ps.printf("\t%s%n\t\t%-7s  %s%n\t\t%-7s  %s%n\t\t%-7s  %d%n", pfxlen, RDSTR, rd, NHSTR, nh, LBSTR, label);
                }
            }
        }
        Map<MultipathKey, Multipath> keyMultipathMap = config.getMultipathContainer() == null ? null : config.getMultipathContainer().getMultipath();
        Map<VrfMaxpathKey, VrfMaxpath> keyVrfMaxpathMap = config.getVrfMaxpathContainer() == null ? null : config.getVrfMaxpathContainer().getVrfMaxpath();
        if (keyMultipathMap != null) {
            ps.printf("%nMultipath%n");
            for (Multipath multipath : keyMultipathMap.values()) {
                int afi = multipath.getAfi().intValue();
                int safi = multipath.getSafi().intValue();
                Boolean enabled = multipath.isMultipathEnabled();
                if (enabled) {
                    if (afi == 1 && safi == 5) {
                        ps.printf("\t%-16s  %s%n%n", AFSTR, "vpnv4");
                    } else if (afi == 2 && safi == 5) {
                        ps.printf("\t%-16s  %s%n%n", AFSTR, "vpnv6");
                    } else if (afi == 3 && safi == 6) {
                        ps.printf("\t%-16s  %s%n%n", AFSTR, "evpn");
                    } else {
                        ps.printf("\t%-16s  %s%n%n", AFSTR, "Unknown");
                    }
                    if (keyVrfMaxpathMap != null) {
                        ps.printf("\t%-16s  %s%n", RDSTR, MPSTR);
                        for (VrfMaxpath vrfMaxpath : keyVrfMaxpathMap.values()) {
                            String rd = vrfMaxpath.getRd();
                            int maxpath = vrfMaxpath.getMaxpaths().toJava();
                            ps.printf("\t%-16s  %d%n", rd, maxpath);
                        }
                    }
                }
            }
        }
    } finally {
        if (fileStream != null) {
            fileStream.close();
        }
    }
    return null;
}
Also used : 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) FileNotFoundException(java.io.FileNotFoundException) EbgpMultihop(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighborscontainer.neighbors.EbgpMultihop) AsId(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.AsId) AddressFamilies(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighborscontainer.neighbors.AddressFamilies) UpdateSource(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighborscontainer.neighbors.UpdateSource) Logging(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.Logging) PrintStream(java.io.PrintStream) 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) AddressFamiliesKey(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighborscontainer.neighbors.AddressFamiliesKey) Neighbors(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighborscontainer.Neighbors) Bgp(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp) VrfMaxpath(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.vrfmaxpathcontainer.VrfMaxpath) 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 Server

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.config.rev200120.server.config.Server in project netvirt by opendaylight.

the class DhcpPktHandler method onPacketReceivedInternal.

public void onPacketReceivedInternal(PacketReceived packet) {
    if (!config.isControllerDhcpEnabled()) {
        return;
    }
    Class<? extends PacketInReason> pktInReason = packet.getPacketInReason();
    short tableId = packet.getTableId().getValue().toJava();
    if ((tableId == NwConstants.DHCP_TABLE || tableId == NwConstants.DHCP_TABLE_EXTERNAL_TUNNEL) && isPktInReasonSendtoCtrl(pktInReason)) {
        byte[] inPayload = packet.getPayload();
        Ethernet ethPkt = new Ethernet();
        try {
            ethPkt.deserialize(inPayload, 0, inPayload.length * Byte.SIZE);
        } catch (PacketException e) {
            pktDropCounter.label(UNKNOWN_LABEL).label(UNKNOWN_LABEL).label(PktDropReason.PKT_DESERIALIZATION_ERROR.name()).increment();
            LOG.warn("Failed to decode DHCP Packet.", e);
            LOG.trace("Received packet {}", packet);
            return;
        }
        DHCP pktIn;
        pktIn = getDhcpPktIn(ethPkt);
        if (pktIn != null) {
            LOG.trace("DHCPPkt received: {}", pktIn);
            LOG.trace("Received Packet: {}", packet);
            Uint64 metadata = packet.getMatch().getMetadata().getMetadata();
            long portTag = MetaDataUtil.getLportFromMetadata(metadata).intValue();
            String macAddress = DHCPUtils.byteArrayToString(ethPkt.getSourceMACAddress());
            pktInCounter.label(macAddress).increment();
            Uint64 tunnelId = packet.getMatch().getTunnel() == null ? null : packet.getMatch().getTunnel().getTunnelId();
            String interfaceName = getInterfaceNameFromTag(portTag);
            if (interfaceName == null) {
                pktDropCounter.label(macAddress).label(UNKNOWN_LABEL).label(PktDropReason.INTERFACE_NAME_NOT_FOUND.name()).increment();
                return;
            }
            InterfaceInfo interfaceInfo = interfaceManager.getInterfaceInfoFromOperationalDataStore(interfaceName);
            if (interfaceInfo == null) {
                LOG.error("Failed to get interface info for interface name {}", interfaceName);
                pktDropCounter.label(macAddress).label(interfaceName).label(PktDropReason.INTERFACE_INFO_NOT_FOUND.name()).increment();
                return;
            }
            Port port;
            if (tunnelId != null) {
                port = dhcpExternalTunnelManager.readVniMacToPortCache(tunnelId, macAddress);
            } else {
                port = getNeutronPort(interfaceName);
            }
            Subnet subnet = getNeutronSubnet(port);
            String serverMacAddress = interfaceInfo.getMacAddress();
            String serverIp = null;
            if (subnet != null) {
                java.util.Optional<SubnetToDhcpPort> dhcpPortData = DhcpServiceUtils.getSubnetDhcpPortData(broker, subnet.getUuid().getValue());
                /* If enable_dhcp_service flag was enabled and an ODL network DHCP Port data was made available use
                     * the ports Fixed IP as server IP for DHCP communication.
                     */
                if (dhcpPortData.isPresent()) {
                    serverIp = dhcpPortData.get().getPortFixedip();
                    serverMacAddress = dhcpPortData.get().getPortMacaddress();
                } else {
                    // DHCP Neutron Port not found for this network
                    LOG.error("Neutron DHCP port is not available for the Subnet {} and port {}.", subnet.getUuid(), port.getUuid());
                    pktDropCounter.label(macAddress).label(interfaceName).label(PktDropReason.SUBNET_NOT_FOUND.name()).increment();
                    return;
                }
            } else {
                pktDropCounter.label(macAddress).label(interfaceName).label(PktDropReason.SUBNET_NOT_FOUND.name()).increment();
            }
            DHCP replyPkt = handleDhcpPacket(pktIn, interfaceName, macAddress, port, subnet, serverIp);
            if (replyPkt == null) {
                LOG.warn("Unable to construct reply packet for interface name {}", interfaceName);
                return;
            }
            byte[] pktOut = getDhcpPacketOut(replyPkt, ethPkt, serverMacAddress);
            sendPacketOut(pktOut, macAddress, interfaceInfo.getDpId(), interfaceName, tunnelId);
        }
    }
}
Also used : SubnetToDhcpPort(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dhcpservice.api.rev150710.subnet.dhcp.port.data.SubnetToDhcpPort) Port(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port) PacketException(org.opendaylight.openflowplugin.libraries.liblldp.PacketException) DHCP(org.opendaylight.netvirt.dhcpservice.api.DHCP) SubnetToDhcpPort(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dhcpservice.api.rev150710.subnet.dhcp.port.data.SubnetToDhcpPort) Ethernet(org.opendaylight.genius.mdsalutil.packet.Ethernet) InterfaceInfo(org.opendaylight.genius.interfacemanager.globals.InterfaceInfo) Subnet(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet) Uint64(org.opendaylight.yangtools.yang.common.Uint64)

Example 20 with Server

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.config.rev200120.server.config.Server in project controller by opendaylight.

the class RpcbenchmarkProvider method startTest.

@Override
public ListenableFuture<RpcResult<StartTestOutput>> startTest(final StartTestInput input) {
    LOG.debug("startTest {}", input);
    final RTCClient client;
    RoutedBindingRTCServer routed = null;
    switch(input.getOperation()) {
        case ROUTEDRTC:
            List<InstanceIdentifier<?>> routeIid = new ArrayList<>();
            for (int i = 0; i < input.getNumServers().intValue(); i++) {
                routeIid.add(InstanceIdentifier.create(RpcbenchRpcRoutes.class).child(RpcRoute.class, new RpcRouteKey(Integer.toString(i))));
            }
            routed = new RoutedBindingRTCServer(providerRegistry, Set.copyOf(routeIid));
            client = new RoutedBindingRTClient(consumerRegistry, input.getPayloadSize().intValue(), routeIid);
            break;
        case GLOBALRTC:
            client = new GlobalBindingRTCClient(consumerRegistry, input.getPayloadSize().intValue());
            break;
        default:
            LOG.error("Unsupported server/client type {}", input.getOperation());
            throw new IllegalArgumentException("Unsupported server/client type" + input.getOperation());
    }
    try {
        ExecutorService executor = Executors.newFixedThreadPool(input.getNumClients().intValue());
        final Runnable testRun = () -> client.runTest(input.getIterations().intValue());
        LOG.info("Test Started");
        final long startTime = System.nanoTime();
        for (int i = 0; i < input.getNumClients().intValue(); i++) {
            // FIXME: fools RV_RETURN_VALUE_IGNORED_BAD_PRACTICE, but we should check more
            verifyNotNull(executor.submit(testRun));
        }
        executor.shutdown();
        try {
            executor.awaitTermination(TEST_TIMEOUT, TimeUnit.MINUTES);
        } catch (final InterruptedException e) {
            LOG.error("Out of time: test did not finish within the {} min deadline ", TEST_TIMEOUT);
        }
        long endTime = System.nanoTime();
        LOG.info("Test Done");
        long elapsedTime = endTime - startTime;
        StartTestOutput output = new StartTestOutputBuilder().setRate(Uint32.ZERO).setGlobalRtcClientError(Uint32.valueOf(client.getRpcError())).setGlobalRtcClientOk(Uint32.valueOf(client.getRpcOk())).setExecTime(Uint32.valueOf(TimeUnit.NANOSECONDS.toMillis(elapsedTime))).setRate(Uint32.valueOf((client.getRpcOk() + client.getRpcError()) * 1000000000 / elapsedTime)).build();
        return RpcResultBuilder.success(output).buildFuture();
    } finally {
        if (routed != null) {
            routed.close();
        }
    }
}
Also used : RpcRoute(org.opendaylight.yang.gen.v1.rpcbench.payload.rev150702.rpcbench.rpc.routes.RpcRoute) ArrayList(java.util.ArrayList) ExecutorService(java.util.concurrent.ExecutorService) StartTestOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rpcbenchmark.rev150702.StartTestOutput) StartTestOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rpcbenchmark.rev150702.StartTestOutputBuilder) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) RpcRouteKey(org.opendaylight.yang.gen.v1.rpcbench.payload.rev150702.rpcbench.rpc.routes.RpcRouteKey)

Aggregations

Test (org.junit.Test)7 ArrayList (java.util.ArrayList)6 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)6 InstructionInfo (org.opendaylight.genius.mdsalutil.InstructionInfo)5 MatchInfoBase (org.opendaylight.genius.mdsalutil.MatchInfoBase)5 AllowedAddressPairs (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.AllowedAddressPairs)5 MatchEthernetSource (org.opendaylight.genius.mdsalutil.matches.MatchEthernetSource)4 Uint64 (org.opendaylight.yangtools.yang.common.Uint64)4 AddLspOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.AddLspOutput)3 AddLspOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.AddLspOutput)3 MsgBuilderUtil.createLspTlvs (org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createLspTlvs)2 AsId (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.AsId)2 GracefulRestart (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.GracefulRestart)2 Logging (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.Logging)2 Multipath (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.multipathcontainer.Multipath)2 MultipathKey (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.multipathcontainer.MultipathKey)2 Neighbors (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighborscontainer.Neighbors)2 NeighborsKey (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighborscontainer.NeighborsKey)2 Networks (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.networkscontainer.Networks)2 NetworksKey (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.networkscontainer.NetworksKey)2