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;
}
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;
}
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());
}
}
}
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));
}
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;
}
Aggregations