use of org.onosproject.driver.optical.flowrule.CrossConnectCache in project onos by opennetworkinglab.
the class LumentumSdnRoadmFlowRuleProgrammable method applyFlowRules.
@Override
public Collection<FlowRule> applyFlowRules(Collection<FlowRule> rules) {
try {
snmp = new LumentumSnmpDevice(data().deviceId());
} catch (IOException e) {
log.error("Failed to connect to device: ", e);
}
// Line ports
DeviceService deviceService = this.handler().get(DeviceService.class);
List<Port> ports = deviceService.getPorts(data().deviceId());
List<PortNumber> linePorts = ports.subList(ports.size() - 2, ports.size()).stream().map(p -> p.number()).collect(Collectors.toList());
// Apply the valid rules on the device
Collection<FlowRule> added = rules.stream().map(r -> new CrossConnectFlowRule(r, linePorts)).filter(xc -> installCrossConnect(xc)).collect(Collectors.toList());
// Cache the cookie/priority
CrossConnectCache cache = this.handler().get(CrossConnectCache.class);
added.forEach(xc -> cache.set(Objects.hash(data().deviceId(), xc.selector(), xc.treatment()), xc.id(), xc.priority()));
return added;
}
use of org.onosproject.driver.optical.flowrule.CrossConnectCache in project onos by opennetworkinglab.
the class LumentumSdnRoadmFlowRuleProgrammable method fetchRules.
// Returns the currently installed flow entries on the device.
private List<FlowRule> fetchRules(OID oid, boolean isAdd, PortNumber linePort) {
List<FlowRule> rules = new LinkedList<>();
for (TreeEvent event : snmp.get(oid)) {
if (event == null) {
continue;
}
VariableBinding[] varBindings = event.getVariableBindings();
for (VariableBinding varBinding : varBindings) {
CrossConnectCache cache = this.handler().get(CrossConnectCache.class);
if (varBinding.getVariable().toInt() == IN_SERVICE) {
int channel = varBinding.getOid().removeLast();
PortNumber addDropPort = getAddDropPort(channel, isAdd);
if (addDropPort == null) {
continue;
}
TrafficSelector selector = DefaultTrafficSelector.builder().matchInPort(isAdd ? addDropPort : linePort).add(Criteria.matchOchSignalType(OchSignalType.FIXED_GRID)).add(Criteria.matchLambda(toOchSignal(channel))).build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(isAdd ? linePort : addDropPort).build();
// Lookup flow ID and priority
int hash = Objects.hash(data().deviceId(), selector, treatment);
Pair<FlowId, Integer> lookup = cache.get(hash);
if (lookup == null) {
continue;
}
FlowRule fr = DefaultFlowRule.builder().forDevice(data().deviceId()).makePermanent().withSelector(selector).withTreatment(treatment).withPriority(lookup.getRight()).withCookie(lookup.getLeft().value()).build();
rules.add(fr);
}
}
}
return rules;
}
use of org.onosproject.driver.optical.flowrule.CrossConnectCache in project onos by opennetworkinglab.
the class LumentumSdnRoadmFlowRuleProgrammable method removeFlowRules.
@Override
public Collection<FlowRule> removeFlowRules(Collection<FlowRule> rules) {
try {
snmp = new LumentumSnmpDevice(data().deviceId());
} catch (IOException e) {
log.error("Failed to connect to device: ", e);
}
// Line ports
DeviceService deviceService = this.handler().get(DeviceService.class);
List<Port> ports = deviceService.getPorts(data().deviceId());
List<PortNumber> linePorts = ports.subList(ports.size() - 2, ports.size()).stream().map(p -> p.number()).collect(Collectors.toList());
// Apply the valid rules on the device
Collection<FlowRule> removed = rules.stream().map(r -> new CrossConnectFlowRule(r, linePorts)).filter(xc -> removeCrossConnect(xc)).collect(Collectors.toList());
// Remove flow rule from cache
CrossConnectCache cache = this.handler().get(CrossConnectCache.class);
removed.forEach(xc -> cache.remove(Objects.hash(data().deviceId(), xc.selector(), xc.treatment())));
return removed;
}
Aggregations