use of org.onosproject.net.flow.DefaultFlowEntry in project onos by opennetworkinglab.
the class FlowRuleProgrammableServerImpl method getFlowEntries.
@Override
public Collection<FlowEntry> getFlowEntries() {
DeviceId deviceId = getDeviceId();
checkNotNull(deviceId, MSG_DEVICE_ID_NULL);
// Expected FlowEntries installed through ONOS
FlowRuleService flowService = getHandler().get(FlowRuleService.class);
Iterable<FlowEntry> flowEntries = flowService.getFlowEntries(deviceId);
// Hit the path that provides the server's flow rules
InputStream response = null;
try {
response = getController().get(deviceId, URL_RULE_MANAGEMENT, JSON);
} catch (ProcessingException pEx) {
log.error("Failed to get NIC flow entries from device: {}", deviceId);
return Collections.EMPTY_LIST;
}
// Load the JSON into objects
ObjectMapper mapper = new ObjectMapper();
ObjectNode objNode = null;
try {
Map<String, Object> jsonMap = mapper.readValue(response, Map.class);
JsonNode jsonNode = mapper.convertValue(jsonMap, JsonNode.class);
objNode = (ObjectNode) jsonNode;
} catch (IOException ioEx) {
log.error("Failed to get NIC flow entries from device: {}", deviceId);
return Collections.EMPTY_LIST;
}
if (objNode == null) {
log.error("Failed to get NIC flow entries from device: {}", deviceId);
return Collections.EMPTY_LIST;
}
JsonNode scsNode = objNode.path(PARAM_RULES);
// Here we store the trully installed rules
Collection<FlowEntry> actualFlowEntries = Sets.<FlowEntry>newConcurrentHashSet();
for (JsonNode scNode : scsNode) {
String scId = get(scNode, PARAM_ID);
String rxFilter = get(scNode.path(PARAM_NIC_RX_FILTER), PARAM_NIC_RX_METHOD);
// Only Flow-based RxFilter is permitted
if (RxFilter.getByName(rxFilter) != RxFilter.FLOW) {
log.warn("Device with Rx filter {} is not managed by this driver", rxFilter.toString().toUpperCase());
continue;
}
// Each device might have multiple NICs
for (JsonNode nicNode : scNode.path(PARAM_NICS)) {
JsonNode cpusNode = nicNode.path(PARAM_CPUS);
// Each NIC can dispatch to multiple CPU cores
for (JsonNode cpuNode : cpusNode) {
String cpuId = get(cpuNode, PARAM_ID);
JsonNode rulesNode = cpuNode.path(PARAM_RULES);
// Multiple rules might correspond to each CPU core
for (JsonNode ruleNode : rulesNode) {
long ruleId = ruleNode.path(PARAM_ID).asLong();
String ruleContent = get(ruleNode, PARAM_RULE_CONTENT);
// Search for this rule ID in ONOS's store
FlowRule r = findRuleInFlowEntries(flowEntries, ruleId);
// Local rule, not present in the controller => Ignore
if (r == null) {
continue;
// Rule trully present in the data plane => Add
} else {
actualFlowEntries.add(new DefaultFlowEntry(r, FlowEntry.FlowEntryState.ADDED, 0, 0, 0));
}
}
}
}
}
return actualFlowEntries;
}
use of org.onosproject.net.flow.DefaultFlowEntry in project fabric-tna by stratum.
the class MockFlowRuleService method apply.
@Override
public void apply(FlowRuleOperations ops) {
AtomicBoolean thisSuccess = new AtomicBoolean(success);
ops.stages().forEach(stage -> stage.forEach(flow -> {
if (errorFlow == flow.rule().id().value()) {
thisSuccess.set(false);
} else {
switch(flow.type()) {
case ADD:
case // TODO is this the right behavior for modify?
MODIFY:
((DefaultFlowEntry) flow.rule()).setState(FlowEntry.FlowEntryState.ADDED);
flows.add(flow.rule());
break;
case REMOVE:
// Remove and add in REMOVED state
flows.remove(flow.rule());
((DefaultFlowEntry) flow.rule()).setState(FlowEntry.FlowEntryState.REMOVED);
flows.add(flow.rule());
break;
default:
break;
}
}
}));
if (thisSuccess.get()) {
ops.callback().onSuccess(ops);
} else {
ops.callback().onError(ops);
}
}
use of org.onosproject.net.flow.DefaultFlowEntry in project onos by opennetworkinglab.
the class LumentumSdnRoadmFlowRuleProgrammable method getFlowEntries.
@Override
public Collection<FlowEntry> getFlowEntries() {
try {
snmp = new LumentumSnmpDevice(handler().data().deviceId());
} catch (IOException e) {
log.error("Failed to connect to device: ", e);
return Collections.emptyList();
}
// Line in is last but one port, line out is last
DeviceService deviceService = this.handler().get(DeviceService.class);
List<Port> ports = deviceService.getPorts(data().deviceId());
if (ports.size() < 2) {
return Collections.emptyList();
}
PortNumber lineIn = ports.get(ports.size() - 2).number();
PortNumber lineOut = ports.get(ports.size() - 1).number();
Collection<FlowEntry> entries = Lists.newLinkedList();
// Add rules
OID addOid = new OID(CTRL_CHANNEL_STATE + "1");
entries.addAll(fetchRules(addOid, true, lineOut).stream().map(fr -> new DefaultFlowEntry(fr, FlowEntry.FlowEntryState.ADDED, 0, 0, 0)).collect(Collectors.toList()));
// Drop rules
OID dropOid = new OID(CTRL_CHANNEL_STATE + "2");
entries.addAll(fetchRules(dropOid, false, lineIn).stream().map(fr -> new DefaultFlowEntry(fr, FlowEntry.FlowEntryState.ADDED, 0, 0, 0)).collect(Collectors.toList()));
return entries;
}
use of org.onosproject.net.flow.DefaultFlowEntry in project onos by opennetworkinglab.
the class GnmiTerminalDeviceFlowRuleProgrammable method getFlowEntries.
@Override
public Collection<FlowEntry> getFlowEntries() {
// TODO: currently, we store flow rules in a cluster store. Should check if rule/config exists via gNMI.
if (!setupBehaviour("getFlowEntries")) {
return Collections.emptyList();
}
DeviceConnectionCache cache = getConnectionCache();
Set<FlowRule> cachedRules = cache.get(deviceId);
if (cachedRules == null) {
return ImmutableList.of();
}
return cachedRules.stream().filter(Objects::nonNull).map(r -> new DefaultFlowEntry(r, FlowEntry.FlowEntryState.ADDED, 0, 0, 0)).collect(Collectors.toList());
}
use of org.onosproject.net.flow.DefaultFlowEntry in project onos by opennetworkinglab.
the class FlowRuleManagerTest method flowRemoved.
@Test
public void flowRemoved() {
FlowRule f1 = addFlowRule(1);
FlowRule f2 = addFlowRule(2);
StoredFlowEntry fe1 = new DefaultFlowEntry(f1);
FlowEntry fe2 = new DefaultFlowEntry(f2);
providerService.pushFlowMetrics(DID, ImmutableList.of(fe1, fe2));
service.removeFlowRules(f1);
// FIXME modification of "stored" flow entry outside of store
fe1.setState(FlowEntryState.REMOVED);
providerService.flowRemoved(fe1);
validateEvents(RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_ADDED, RULE_ADDED, RULE_REMOVE_REQUESTED, RULE_REMOVED);
providerService.flowRemoved(fe1);
validateEvents();
FlowRule f3 = flowRule(3, 3);
FlowEntry fe3 = new DefaultFlowEntry(f3);
service.applyFlowRules(f3);
providerService.pushFlowMetrics(DID, Collections.singletonList(fe3));
validateEvents(RULE_ADD_REQUESTED, RULE_ADDED, RULE_UPDATED);
providerService.flowRemoved(fe3);
validateEvents();
}
Aggregations