use of org.onosproject.net.flow.FlowRuleService in project onos by opennetworkinglab.
the class OFSwitchManager method getFlowEntries.
@Override
public List<FlowEntry> getFlowEntries(NetworkId networkId, DeviceId deviceId) {
FlowRuleService flowRuleService = virtualNetService.get(networkId, FlowRuleService.class);
Iterable<FlowEntry> entries = flowRuleService.getFlowEntries(deviceId);
return Lists.newArrayList(entries);
}
use of org.onosproject.net.flow.FlowRuleService in project onos by opennetworkinglab.
the class OFSwitchManager method getFlowTableStatistics.
@Override
public List<TableStatisticsEntry> getFlowTableStatistics(NetworkId networkId, DeviceId deviceId) {
FlowRuleService flowRuleService = virtualNetService.get(networkId, FlowRuleService.class);
Iterable<TableStatisticsEntry> entries = flowRuleService.getFlowTableStatistics(deviceId);
if (entries == null) {
entries = new ArrayList<>();
}
return Lists.newArrayList(entries);
}
use of org.onosproject.net.flow.FlowRuleService in project onos by opennetworkinglab.
the class OFSwitchManager method processOFAgentStopped.
private void processOFAgentStopped(OFAgent ofAgent) {
devices(ofAgent.networkId()).forEach(deviceId -> {
OFSwitch ofSwitch = ofSwitchMap.get(deviceId);
if (ofSwitch != null) {
disconnectController(ofSwitch, ofAgent.controllers());
}
});
DeviceService deviceService = virtualNetService.get(ofAgent.networkId(), DeviceService.class);
deviceService.removeListener(deviceListener);
PacketService packetService = virtualNetService.get(ofAgent.networkId(), PacketService.class);
packetService.removeProcessor(packetProcessor);
FlowRuleService flowRuleService = virtualNetService.get(ofAgent.networkId(), FlowRuleService.class);
flowRuleService.removeListener(flowRuleListener);
}
use of org.onosproject.net.flow.FlowRuleService in project onos by opennetworkinglab.
the class OpenstackPurgeRulesCommand method doExecute.
@Override
protected void doExecute() {
FlowRuleService flowRuleService = get(FlowRuleService.class);
CoreService coreService = get(CoreService.class);
ApplicationId appId = coreService.getAppId(Constants.OPENSTACK_NETWORKING_APP_ID);
if (appId == null) {
error("Failed to purge OpenStack networking flow rules.");
return;
}
flowRuleService.removeFlowRulesById(appId);
print("Successfully purged flow rules installed by OpenStack networking app.");
boolean result = true;
long timeoutExpiredMs = System.currentTimeMillis() + TIMEOUT_MS;
// we make sure all flow rules are removed from the store
while (stream(flowRuleService.getFlowEntriesById(appId).spliterator(), false).count() > 0) {
long waitMs = timeoutExpiredMs - System.currentTimeMillis();
try {
sleep(SLEEP_MS);
} catch (InterruptedException e) {
log.error("Exception caused during rule purging...");
}
if (stream(flowRuleService.getFlowEntriesById(appId).spliterator(), false).count() == 0) {
break;
} else {
flowRuleService.removeFlowRulesById(appId);
print("Failed to purging flow rules, retrying rule purging...");
}
if (waitMs <= 0) {
result = false;
break;
}
}
if (result) {
print("Successfully purged flow rules!");
} else {
error("Failed to purge flow rules.");
}
}
use of org.onosproject.net.flow.FlowRuleService 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;
}
Aggregations