use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class RoadmManager method removeConnection.
@Override
public void removeConnection(DeviceId deviceId, FlowId flowId) {
checkNotNull(deviceId);
checkNotNull(flowId);
for (FlowEntry entry : flowRuleService.getFlowEntries(deviceId)) {
if (entry.id().equals(flowId)) {
flowRuleService.removeFlowRules(entry);
log.info("Deleted connection {}", entry.id());
break;
}
}
}
use of org.onosproject.net.flow.FlowEntry 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.FlowEntry in project onos by opennetworkinglab.
the class RoadmCrossConnectCommand method dropRule.
/**
* This function drops XC installed on the device, which is matching parsed criteria.
* Takes as an input "global" parameters (passed by user through the console).
* @return - returns number of the rules that were dropped.
*/
protected FlowId dropRule() {
// Preparing parameters
DeviceId device = DeviceId.deviceId(deviceId);
PortNumber inPort = PortNumber.portNumber(srcPort);
PortNumber outPort = PortNumber.portNumber(dstPort);
// Creating some variables
OchSignal ochSignal = null;
PortNumber inputPortNumber = null;
PortNumber outputPortNumber = null;
// Main idea: Go over all flow rules (read out from the storage) of current device and
// filter them based on input and output port with respect to OchSignal
FlowRuleService fr = AbstractShellCommand.get(FlowRuleService.class);
Iterable<FlowEntry> flowRules = fr.getFlowEntries(device);
FlowId flowId = null;
OchSignal referenceSignal = createOchSignal(freq, sw, gridType, channelSpacing);
for (FlowEntry flowRule : flowRules) {
// Taken from FlowRuleParser
for (Criterion c : flowRule.selector().criteria()) {
if (c instanceof OchSignalCriterion) {
ochSignal = ((OchSignalCriterion) c).lambda();
}
if (c instanceof PortCriterion) {
// obtain input port
inputPortNumber = ((PortCriterion) c).port();
}
}
for (Instruction i : flowRule.treatment().immediate()) {
if (i instanceof L0ModificationInstruction.ModOchSignalInstruction) {
ochSignal = ((L0ModificationInstruction.ModOchSignalInstruction) i).lambda();
}
if (i instanceof Instructions.OutputInstruction) {
// obtain output port
outputPortNumber = ((Instructions.OutputInstruction) i).port();
}
}
// If we found match, then let's delete this rule
if ((ochSignal.centralFrequency().equals(referenceSignal.centralFrequency())) & (ochSignal.slotWidth().equals(referenceSignal.slotWidth())) & (inputPortNumber.equals(inPort)) & (outputPortNumber.equals(outPort))) {
flowId = flowRule.id();
RoadmService manager = AbstractShellCommand.get(RoadmService.class);
manager.removeConnection(device, flowId);
print("Dropping existing XC from the device %s", deviceId);
return flowId;
}
}
return null;
}
use of org.onosproject.net.flow.FlowEntry 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();
}
use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class FlowRuleManagerTest method extraneousFlow.
@Test
public void extraneousFlow() {
FlowRule f1 = flowRule(1, 1);
FlowRule f2 = flowRule(2, 2);
FlowRule f3 = flowRule(3, 3);
mgr.applyFlowRules(f1, f2);
// FlowRule updatedF1 = flowRule(f1, FlowRuleState.ADDED);
// FlowRule updatedF2 = flowRule(f2, FlowRuleState.ADDED);
// FlowRule updatedF3 = flowRule(f3, FlowRuleState.ADDED);
FlowEntry fe1 = new DefaultFlowEntry(f1);
FlowEntry fe2 = new DefaultFlowEntry(f2);
FlowEntry fe3 = new DefaultFlowEntry(f3);
providerService.pushFlowMetrics(DID, Lists.newArrayList(fe1, fe2, fe3));
validateEvents(RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_ADDED, RULE_ADDED);
}
Aggregations