Search in sources :

Example 71 with FlowEntry

use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.

the class StatsFlowRuleManager method getUnderlayFlowInfos.

@Override
public Set<FlowInfo> getUnderlayFlowInfos() {
    Set<FlowInfo> flowInfos = Sets.newConcurrentHashSet();
    for (Device device : getUnderlayDevices()) {
        if (!isEdgeSwitch(device.id())) {
            continue;
        }
        for (FlowEntry entry : flowRuleService.getFlowEntries(device.id())) {
            FlowInfo.Builder fBuilder = new DefaultFlowInfo.DefaultBuilder();
            TrafficSelector selector = entry.selector();
            Criterion inPort = selector.getCriterion(Criterion.Type.IN_PORT);
            Criterion dstIpCriterion = selector.getCriterion(Criterion.Type.IPV4_DST);
            if (inPort != null && dstIpCriterion != null) {
                IpAddress srcIp = getIpAddress(device, (PortCriterion) inPort);
                IpAddress dstIp = ((IPCriterion) dstIpCriterion).ip().address();
                if (srcIp == null) {
                    continue;
                }
                fBuilder.withFlowType(FLOW_TYPE_SONA).withSrcIp(IpPrefix.valueOf(srcIp, ARBITRARY_LENGTH)).withDstIp(IpPrefix.valueOf(dstIp, ARBITRARY_LENGTH)).withSrcMac(getMacAddress(srcIp)).withDstMac(getMacAddress(dstIp)).withInputInterfaceId(getInterfaceId(srcIp)).withOutputInterfaceId(getInterfaceId(dstIp)).withDeviceId(entry.deviceId());
                StatsInfo.Builder sBuilder = new DefaultStatsInfo.DefaultBuilder();
                sBuilder.withStartupTime(System.currentTimeMillis()).withFstPktArrTime(System.currentTimeMillis()).withLstPktOffset((int) (REFRESH_INTERVAL * MILLISECONDS)).withCurrAccPkts((int) entry.packets()).withCurrAccBytes(entry.bytes()).withErrorPkts((short) 0).withDropPkts((short) 0);
                fBuilder.withStatsInfo(sBuilder.build());
                FlowInfo flowInfo = mergeFlowInfo(fBuilder.build(), fBuilder, sBuilder);
                flowInfos.add(flowInfo);
            }
        }
    }
    return flowInfos;
}
Also used : FlowInfo(org.onosproject.openstacktelemetry.api.FlowInfo) DefaultFlowInfo(org.onosproject.openstacktelemetry.api.DefaultFlowInfo) StatsInfo(org.onosproject.openstacktelemetry.api.StatsInfo) DefaultStatsInfo(org.onosproject.openstacktelemetry.api.DefaultStatsInfo) Criterion(org.onosproject.net.flow.criteria.Criterion) UdpPortCriterion(org.onosproject.net.flow.criteria.UdpPortCriterion) IPProtocolCriterion(org.onosproject.net.flow.criteria.IPProtocolCriterion) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) TcpPortCriterion(org.onosproject.net.flow.criteria.TcpPortCriterion) Device(org.onosproject.net.Device) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) IpAddress(org.onlab.packet.IpAddress) FlowEntry(org.onosproject.net.flow.FlowEntry)

Example 72 with FlowEntry

use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.

the class StatsFlowRuleManager method getOverlayFlowInfos.

@Override
public Set<FlowInfo> getOverlayFlowInfos() {
    Set<FlowInfo> flowInfos = Sets.newConcurrentHashSet();
    // obtain all flow rule entries installed by telemetry app
    for (FlowEntry entry : flowRuleService.getFlowEntriesById(telemetryAppId)) {
        FlowInfo.Builder fBuilder = new DefaultFlowInfo.DefaultBuilder();
        TrafficSelector selector = entry.selector();
        IPCriterion srcIp = (IPCriterion) selector.getCriterion(IPV4_SRC);
        IPCriterion dstIp = (IPCriterion) selector.getCriterion(IPV4_DST);
        IPProtocolCriterion ipProtocol = (IPProtocolCriterion) selector.getCriterion(IP_PROTO);
        fBuilder.withFlowType(FLOW_TYPE_SONA).withSrcIp(srcIp.ip()).withDstIp(dstIp.ip());
        if (ipProtocol != null) {
            fBuilder.withProtocol((byte) ipProtocol.protocol());
            if (ipProtocol.protocol() == PROTOCOL_TCP) {
                TcpPortCriterion tcpSrc = (TcpPortCriterion) selector.getCriterion(TCP_SRC);
                TcpPortCriterion tcpDst = (TcpPortCriterion) selector.getCriterion(TCP_DST);
                fBuilder.withSrcPort(tcpSrc.tcpPort());
                fBuilder.withDstPort(tcpDst.tcpPort());
            } else if (ipProtocol.protocol() == PROTOCOL_UDP) {
                UdpPortCriterion udpSrc = (UdpPortCriterion) selector.getCriterion(UDP_SRC);
                UdpPortCriterion udpDst = (UdpPortCriterion) selector.getCriterion(UDP_DST);
                fBuilder.withSrcPort(udpSrc.udpPort());
                fBuilder.withDstPort(udpDst.udpPort());
            } else {
                log.debug("Other protocol: {}", ipProtocol.protocol());
            }
        }
        fBuilder.withSrcMac(getMacAddress(srcIp.ip().address())).withDstMac(getMacAddress(dstIp.ip().address())).withInputInterfaceId(getInterfaceId(srcIp.ip().address())).withOutputInterfaceId(getInterfaceId(dstIp.ip().address())).withVlanId(getVlanId(srcIp.ip().address())).withDeviceId(entry.deviceId());
        StatsInfo.Builder sBuilder = new DefaultStatsInfo.DefaultBuilder();
        sBuilder.withStartupTime(System.currentTimeMillis()).withFstPktArrTime(System.currentTimeMillis()).withLstPktOffset((int) (REFRESH_INTERVAL * MILLISECONDS)).withCurrAccPkts((int) entry.packets()).withCurrAccBytes(entry.bytes()).withErrorPkts((short) 0).withDropPkts((short) 0);
        fBuilder.withStatsInfo(sBuilder.build());
        FlowInfo flowInfo = mergeFlowInfo(fBuilder.build(), fBuilder, sBuilder);
        flowInfos.add(flowInfo);
        log.debug("FlowInfo: \n{}", flowInfo.toString());
    }
    return flowInfos;
}
Also used : FlowInfo(org.onosproject.openstacktelemetry.api.FlowInfo) DefaultFlowInfo(org.onosproject.openstacktelemetry.api.DefaultFlowInfo) StatsInfo(org.onosproject.openstacktelemetry.api.StatsInfo) DefaultStatsInfo(org.onosproject.openstacktelemetry.api.DefaultStatsInfo) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) TcpPortCriterion(org.onosproject.net.flow.criteria.TcpPortCriterion) IPProtocolCriterion(org.onosproject.net.flow.criteria.IPProtocolCriterion) UdpPortCriterion(org.onosproject.net.flow.criteria.UdpPortCriterion) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) FlowEntry(org.onosproject.net.flow.FlowEntry)

Example 73 with FlowEntry

use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.

the class VirtualFlowsListCommand method printFlows.

/**
 * Prints flows.
 *
 * @param d     the device
 * @param flows the set of flows for that device
 * @param coreService core system service
 */
protected void printFlows(Device d, List<FlowEntry> flows, CoreService coreService) {
    List<FlowEntry> filteredFlows = flows.stream().filter(f -> contentFilter.filter(f)).collect(Collectors.toList());
    boolean empty = filteredFlows == null || filteredFlows.isEmpty();
    print("deviceId=%s, flowRuleCount=%d", d.id(), empty ? 0 : filteredFlows.size());
    if (empty || countOnly) {
        return;
    }
    for (FlowEntry f : filteredFlows) {
        if (shortOutput) {
            print(SHORT_FORMAT, f.state(), f.bytes(), f.packets(), f.tableId(), f.priority(), f.selector().criteria(), printTreatment(f.treatment()));
        } else {
            ApplicationId appId = coreService.getAppId(f.appId());
            print(LONG_FORMAT, Long.toHexString(f.id().value()), f.state(), f.bytes(), f.packets(), f.life(), f.liveType(), f.priority(), f.tableId(), appId != null ? appId.name() : "<none>", f.selector().criteria(), f.treatment());
        }
    }
}
Also used : StringFilter(org.onlab.util.StringFilter) Comparators(org.onosproject.utils.Comparators) FlowEntryState(org.onosproject.net.flow.FlowEntry.FlowEntryState) CoreService(org.onosproject.core.CoreService) DeviceService(org.onosproject.net.device.DeviceService) FlowEntry(org.onosproject.net.flow.FlowEntry) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Command(org.apache.karaf.shell.api.action.Command) ArrayList(java.util.ArrayList) FlowRuleService(org.onosproject.net.flow.FlowRuleService) FlowRuleStatusCompleter(org.onosproject.cli.net.FlowRuleStatusCompleter) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) VirtualNetworkService(org.onosproject.incubator.net.virtual.VirtualNetworkService) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) JsonNode(com.fasterxml.jackson.databind.JsonNode) PlaceholderCompleter(org.onosproject.cli.PlaceholderCompleter) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Device(org.onosproject.net.Device) Predicate(java.util.function.Predicate) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Argument(org.apache.karaf.shell.api.action.Argument) Collectors(java.util.stream.Collectors) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) TreeMap(java.util.TreeMap) Service(org.apache.karaf.shell.api.action.lifecycle.Service) Completion(org.apache.karaf.shell.api.action.Completion) Option(org.apache.karaf.shell.api.action.Option) DeviceId(org.onosproject.net.DeviceId) Collections(java.util.Collections) SortedMap(java.util.SortedMap) ApplicationId(org.onosproject.core.ApplicationId) FlowEntry(org.onosproject.net.flow.FlowEntry)

Example 74 with FlowEntry

use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.

the class VirtualNetworkFlowRuleManager method removeFlowRulesById.

@Override
public void removeFlowRulesById(ApplicationId id) {
    Set<FlowRule> flowEntries = Sets.newHashSet();
    for (Device d : deviceService.getDevices()) {
        for (FlowEntry flowEntry : store.getFlowEntries(networkId(), d.id())) {
            if (flowEntry.appId() == id.id()) {
                flowEntries.add(flowEntry);
            }
        }
    }
    removeFlowRules(Iterables.toArray(flowEntries, FlowRule.class));
}
Also used : Device(org.onosproject.net.Device) FlowRule(org.onosproject.net.flow.FlowRule) FlowEntry(org.onosproject.net.flow.FlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry)

Example 75 with FlowEntry

use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.

the class FlowRuleManager method getFlowEntriesById.

@Override
public Iterable<FlowEntry> getFlowEntriesById(ApplicationId id) {
    checkPermission(FLOWRULE_READ);
    Set<FlowEntry> flowEntries = Sets.newHashSet();
    for (Device d : deviceService.getDevices()) {
        for (FlowEntry flowEntry : store.getFlowEntries(d.id())) {
            if (flowEntry.appId() == id.id()) {
                flowEntries.add(flowEntry);
            }
        }
    }
    return flowEntries;
}
Also used : Device(org.onosproject.net.Device) FlowEntry(org.onosproject.net.flow.FlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry)

Aggregations

FlowEntry (org.onosproject.net.flow.FlowEntry)122 DefaultFlowEntry (org.onosproject.net.flow.DefaultFlowEntry)61 FlowRule (org.onosproject.net.flow.FlowRule)51 Test (org.junit.Test)31 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)31 FlowRuleService (org.onosproject.net.flow.FlowRuleService)26 ArrayList (java.util.ArrayList)24 StoredFlowEntry (org.onosproject.net.flow.StoredFlowEntry)23 DeviceId (org.onosproject.net.DeviceId)20 Device (org.onosproject.net.Device)19 PortNumber (org.onosproject.net.PortNumber)17 Instruction (org.onosproject.net.flow.instructions.Instruction)16 TrafficSelector (org.onosproject.net.flow.TrafficSelector)15 List (java.util.List)14 DeviceService (org.onosproject.net.device.DeviceService)14 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)13 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)13 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)12 HashSet (java.util.HashSet)12 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)11