use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class DefaultCheckLoop method findLoop.
/**
* Enter of the loop checking algorithm.
*
* @return the set of loop results; empty, if there is no loop
*/
private Set<NetworkAnomaly> findLoop() {
getNetworkSnapshot();
loops = new HashSet<>();
excludeDeviceId = new HashSet<>();
for (Device device : accessDevices) {
if (excludeDeviceId.contains(device.id())) {
continue;
}
List<FlowEntry> availableFlowEntries = new ArrayList<>();
flowEntryInfo.get(device.id()).forEach(flowEntry -> {
if (flowEntry.state() == ADDED) {
availableFlowEntries.add(flowEntry);
}
});
List<FlowEntry> sortedFlowEntries = sortFlowTable(availableFlowEntries);
for (FlowEntry flow : sortedFlowEntries) {
TsLoopPacket pkt = matchBuilder(flow.selector().criteria(), null);
pkt.pushPathFlow(flow);
List<Instruction> inst = flow.treatment().immediate();
for (Instruction instOne : inst) {
// Attention !!!
// if you would like to modify the code here,
// please MAKE VERY SURE that you are clear with
// the relationship of any invoked methods, and
// the relationship of params which are passed in and out.
processOneInstruction(instOne, device.id(), null, pkt, true, flow);
}
}
}
return loops;
}
use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class DefaultOFSwitch method processFlowMod.
private void processFlowMod(OFFlowMod flowMod) {
// convert OFFlowMod to FLowRule object
OFAgentVirtualFlowEntryBuilder flowEntryBuilder = new OFAgentVirtualFlowEntryBuilder(deviceId, flowMod, driverService);
FlowEntry flowEntry = flowEntryBuilder.build();
flowRuleService.applyFlowRules(flowEntry);
}
use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class DefaultOFSwitch method processStatsRequest.
@Override
public void processStatsRequest(Channel channel, OFMessage msg) {
if (msg.getType() != OFType.STATS_REQUEST) {
log.warn("Ignoring message of type {}.", msg.getType());
return;
}
OFStatsRequest ofStatsRequest = (OFStatsRequest) msg;
OFStatsReply ofStatsReply = null;
switch(ofStatsRequest.getStatsType()) {
case PORT_DESC:
List<OFPortDesc> portDescs = new ArrayList<>();
Set<Port> ports = ofSwitchService.ports(networkId, deviceId);
ports.forEach(port -> {
OFPortDesc ofPortDesc = portDesc(port);
portDescs.add(ofPortDesc);
});
ofStatsReply = FACTORY.buildPortDescStatsReply().setXid(msg.getXid()).setEntries(portDescs).build();
break;
case PORT:
OFPortStatsRequest portStatsRequest = (OFPortStatsRequest) msg;
OFPort ofPort = portStatsRequest.getPortNo();
List<OFPortStatsEntry> portStatsEntries = new ArrayList<>();
List<PortStatistics> portStatistics = ofSwitchService.getPortStatistics(networkId, deviceId);
if (ofPort.equals(OFPort.ANY)) {
portStatistics.forEach(portStatistic -> {
OFPortStatsEntry ofPortStatsEntry = portStatsEntry(portStatistic);
portStatsEntries.add(ofPortStatsEntry);
});
}
ofStatsReply = FACTORY.buildPortStatsReply().setEntries(portStatsEntries).setXid(msg.getXid()).build();
break;
case METER_FEATURES:
OFMeterFeatures ofMeterFeatures = FACTORY.buildMeterFeatures().build();
ofStatsReply = FACTORY.buildMeterFeaturesStatsReply().setXid(msg.getXid()).setFeatures(ofMeterFeatures).build();
break;
case FLOW:
List<OFFlowStatsEntry> flowStatsEntries = new ArrayList<>();
List<FlowEntry> flowStats = ofSwitchService.getFlowEntries(networkId, deviceId);
flowStats.forEach(flowEntry -> {
OFFlowStatsEntry ofFlowStatsEntry = ofFlowStatsEntry(flowEntry);
flowStatsEntries.add(ofFlowStatsEntry);
});
ofStatsReply = FACTORY.buildFlowStatsReply().setEntries(flowStatsEntries).setXid(msg.getXid()).build();
break;
case TABLE:
List<OFTableStatsEntry> ofTableStatsEntries = new ArrayList<>();
List<TableStatisticsEntry> tableStats = ofSwitchService.getFlowTableStatistics(networkId, deviceId);
tableStats.forEach(tableStatisticsEntry -> {
OFTableStatsEntry ofFlowStatsEntry = ofFlowTableStatsEntry(tableStatisticsEntry);
ofTableStatsEntries.add(ofFlowStatsEntry);
});
ofStatsReply = FACTORY.buildTableStatsReply().setEntries(ofTableStatsEntries).setXid(msg.getXid()).build();
break;
case GROUP:
List<Group> groupStats = ofSwitchService.getGroups(networkId, deviceId);
List<OFGroupStatsEntry> ofGroupStatsEntries = new ArrayList<>();
groupStats.forEach(group -> {
OFGroupStatsEntry entry = ofGroupStatsEntry(group);
ofGroupStatsEntries.add(entry);
});
ofStatsReply = FACTORY.buildGroupStatsReply().setEntries(ofGroupStatsEntries).setXid(msg.getXid()).build();
break;
case GROUP_DESC:
List<OFGroupDescStatsEntry> ofGroupDescStatsEntries = new ArrayList<>();
List<Group> groupStats2 = ofSwitchService.getGroups(networkId, deviceId);
groupStats2.forEach(group -> {
OFGroupDescStatsEntry entry = ofGroupDescStatsEntry(group);
ofGroupDescStatsEntries.add(entry);
});
ofStatsReply = FACTORY.buildGroupDescStatsReply().setEntries(ofGroupDescStatsEntries).setXid(msg.getXid()).build();
break;
case DESC:
ofStatsReply = FACTORY.buildDescStatsReply().setXid(msg.getXid()).build();
break;
default:
log.debug("Functionality not yet supported for type {} statsType{} msg {}", msg.getType(), ofStatsRequest.getStatsType(), msg);
break;
}
if (ofStatsReply != null) {
log.trace("request {}; reply {}", msg, ofStatsReply);
channel.writeAndFlush(Collections.singletonList(ofStatsReply));
}
}
use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class RoadmManager method channelAvailable.
@Override
public boolean channelAvailable(DeviceId deviceId, OchSignal ochSignal) {
checkNotNull(deviceId);
checkNotNull(ochSignal);
for (FlowEntry entry : flowRuleService.getFlowEntries(deviceId)) {
if (ChannelData.fromFlow(entry).ochSignal().equals(ochSignal)) {
return false;
}
}
return true;
}
use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class FlowAnalyzer method analyze.
/**
* Analyzes and prints out a report on the status of every flow entry inside
* the network. The possible states are: Cleared (implying that the entry leads to
* a host), Cycle (implying that it is part of cycle), and Black Hole (implying
* that the entry does not lead to a single host).
*
* @return result string
*/
public String analyze() {
graph = topologyService.getGraph(topologyService.currentTopology());
for (TopologyVertex v : graph.getVertexes()) {
DeviceId srcDevice = v.deviceId();
Iterable<FlowEntry> flowTable = flowRuleService.getFlowEntries(srcDevice);
for (FlowEntry flow : flowTable) {
dfs(flow);
}
}
// analyze the cycles to look for "critical flows" that can be removed
// to break the cycle
Set<FlowEntry> critpts = new HashSet<>();
for (FlowEntry flow : label.keySet()) {
if ("Cycle".equals(label.get(flow))) {
Map<FlowEntry, String> labelSaved = label;
label = new HashMap<FlowEntry, String>();
ignoredFlows.add(flow);
for (TopologyVertex v : graph.getVertexes()) {
DeviceId srcDevice = v.deviceId();
Iterable<FlowEntry> flowTable = flowRuleService.getFlowEntries(srcDevice);
for (FlowEntry flow1 : flowTable) {
dfs(flow1);
}
}
boolean replacable = true;
for (FlowEntry flow2 : label.keySet()) {
if ("Cleared".equals(labelSaved.get(flow2)) && !("Cleared".equals(label.get(flow2)))) {
replacable = false;
}
}
if (replacable) {
critpts.add(flow);
}
label = labelSaved;
}
}
for (FlowEntry flow : critpts) {
label.put(flow, "Cycle Critical Point");
}
String s = "\n";
for (FlowEntry flow : label.keySet()) {
s += ("Flow Rule: " + flowEntryRepresentation(flow) + "\n");
s += ("Analysis: " + label.get(flow) + "!\n\n");
}
s += ("Analyzed " + label.keySet().size() + " flows.");
// log.info(s);
return s;
}
Aggregations