use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class OplinkOpticalPowerConfig method setChannelTargetPower.
private boolean setChannelTargetPower(PortNumber port, OchSignal channel, long power) {
log.debug("Set port{} channel{} attenuation.", port, channel.channelSpacing());
FlowRuleService service = handler().get(FlowRuleService.class);
Iterable<FlowEntry> entries = service.getFlowEntries(data().deviceId());
for (FlowEntry entry : entries) {
OplinkCrossConnect crossConnect = OplinkOpticalUtility.fromFlowRule(this, entry);
// The channel port might be input port or output port.
if ((port.equals(crossConnect.getInPort()) || port.equals(crossConnect.getOutPort())) && channel.spacingMultiplier() == crossConnect.getChannel()) {
log.debug("Flow is found, modify the flow with attenuation.");
// Modify attenuation in treatment
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(crossConnect.getOutPort()).extension(new OplinkAttenuation((int) power), data().deviceId()).build();
// Apply the new flow rule
service.applyFlowRules(DefaultFlowRule.builder().forDevice(data().deviceId()).makePermanent().withSelector(entry.selector()).withTreatment(treatment).withPriority(entry.priority()).withCookie(entry.id().value()).build());
return true;
}
}
return false;
}
use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class TapiFlowRuleProgrammable method getFlowEntries.
@Override
public Collection<FlowEntry> getFlowEntries() {
DeviceId deviceId = did();
// TODO this is a blocking call on ADVA OLS, right now using cache.
// return getFlowsFromConnectivityServices(deviceId);
List<FlowEntry> entries = new ArrayList<>();
Set<FlowRule> rules = getConnectionCache().get(deviceId);
if (rules != null) {
rules.forEach(rule -> {
entries.add(new DefaultFlowEntry(rule, FlowEntry.FlowEntryState.ADDED, 0, 0, 0));
});
}
return entries;
}
use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class TapiFlowRuleProgrammable method getFlowsFromConnectivityServices.
// Currently uused because get is a blocking call on ADVA
private Collection<FlowEntry> getFlowsFromConnectivityServices(DeviceId deviceId) {
Set<String> uuids = getUuids(deviceId, handler());
if (uuids.isEmpty()) {
return ImmutableList.of();
}
DeviceConnectionCache cache = getConnectionCache();
if (cache.get(deviceId) == null) {
return ImmutableList.of();
}
List<FlowEntry> entries = new ArrayList<>();
uuids.forEach(uuid -> {
FlowRule rule = cache.get(deviceId, uuid);
if (rule != null) {
entries.add(new DefaultFlowEntry(rule, FlowEntry.FlowEntryState.ADDED, 0, 0, 0));
} else {
log.info("Non existing rule for uuid {}", uuid);
}
});
return entries;
}
use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class ReactiveForwarding method fixBlackhole.
private void fixBlackhole(ConnectPoint egress) {
Set<FlowEntry> rules = getFlowRulesFrom(egress);
Set<SrcDstPair> pairs = findSrcDstPairs(rules);
Map<DeviceId, Set<Path>> srcPaths = new HashMap<>();
for (SrcDstPair sd : pairs) {
// get the edge deviceID for the src host
Host srcHost = hostService.getHost(HostId.hostId(sd.src));
Host dstHost = hostService.getHost(HostId.hostId(sd.dst));
if (srcHost != null && dstHost != null) {
DeviceId srcId = srcHost.location().deviceId();
DeviceId dstId = dstHost.location().deviceId();
log.trace("SRC ID is {}, DST ID is {}", srcId, dstId);
cleanFlowRules(sd, egress.deviceId());
Set<Path> shortestPaths = srcPaths.get(srcId);
if (shortestPaths == null) {
shortestPaths = topologyService.getPaths(topologyService.currentTopology(), egress.deviceId(), srcId);
srcPaths.put(srcId, shortestPaths);
}
backTrackBadNodes(shortestPaths, dstId, sd);
}
}
}
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