use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class OpenstackTroubleshootManager method checkFlowRule.
/**
* Checks whether flow rules with the given IP and criterion are added or not.
*
* @param ip IP address
* @param ipType IP criterion type (IPV4_DST or IPV4_SRC)
* @return true if the flow rule is added, false otherwise
*/
private boolean checkFlowRule(String ip, Criterion.Type ipType) {
for (FlowEntry entry : flowRuleService.getFlowEntriesById(appId)) {
TrafficSelector selector = entry.selector();
IPCriterion ipCriterion = (IPCriterion) selector.getCriterion(ipType);
if (ipCriterion != null && ip.equals(ipCriterion.ip().address().toString()) && entry.state() == ADDED) {
return true;
}
}
return false;
}
use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class IntentFilter method getFlowEntries.
/**
* Finds all flow entries created by FlowObjectiveIntent.
*
* @param intent FlowObjectiveIntent Object
* @return set of flow entries created by FlowObjectiveIntent
*/
private List<FlowEntry> getFlowEntries(FlowObjectiveIntent intent) {
List<FlowEntry> flowEntries = new ArrayList<>();
Iterator<Objective> objectives = intent.objectives().iterator();
Iterator<DeviceId> devices = intent.devices().iterator();
DefaultNextObjective nextObjective = null;
DefaultForwardingObjective forwardObjective;
Objective objective;
DeviceId deviceId;
FlowEntry flowEntry;
while (objectives.hasNext()) {
objective = objectives.next();
deviceId = devices.next();
if (objective instanceof NextObjective) {
nextObjective = (DefaultNextObjective) objective;
} else if (objective instanceof ForwardingObjective) {
forwardObjective = (DefaultForwardingObjective) objective;
FlowRule.Builder builder = DefaultFlowRule.builder().forDevice(deviceId).withSelector(forwardObjective.selector()).withPriority(intent.priority()).fromApp(intent.appId()).makePermanent();
if (nextObjective != null) {
builder.withTreatment(nextObjective.next().iterator().next());
}
FlowRule flowRule = builder.build();
flowEntry = getFlowEntry(flowRule);
if (flowEntry != null) {
flowEntries.add(flowEntry);
}
}
}
return flowEntries;
}
use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class IntentFilter method getFlowEntries.
/**
* Finds all flow entries created by FlowRuleIntent.
*
* @param intent FlowRuleIntent Object
* @return set of flow entries created by FlowRuleIntent
*/
private List<FlowEntry> getFlowEntries(FlowRuleIntent intent) {
List<FlowEntry> flowEntries = new ArrayList<>();
Collection<FlowRule> flowRules = intent.flowRules();
FlowEntry flowEntry;
for (FlowRule flowRule : flowRules) {
flowEntry = getFlowEntry(flowRule);
if (flowEntry != null) {
flowEntries.add(flowEntry);
}
}
return flowEntries;
}
use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class VirtualNetworkFlowRuleManagerTest method getFlowEntries.
@Test
public void getFlowEntries() {
assertTrue("store should be empty", Sets.newHashSet(vnetFlowRuleService1.getFlowEntries(VDID1)).isEmpty());
assertTrue("store should be empty", Sets.newHashSet(vnetFlowRuleService2.getFlowEntries(VDID1)).isEmpty());
FlowRule f1 = addFlowRule(1);
FlowRule f2 = addFlowRule(2);
FlowEntry fe1 = new DefaultFlowEntry(f1);
FlowEntry fe2 = new DefaultFlowEntry(f2);
assertEquals("2 rules should exist", 2, flowCount(vnetFlowRuleService1));
assertEquals("0 rules should exist", 0, flowCount(vnetFlowRuleService2));
providerService1.pushFlowMetrics(VDID1, ImmutableList.of(fe1, fe2));
validateEvents(listener1, RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_ADDED, RULE_ADDED);
addFlowRule(1);
assertEquals("should still be 2 rules", 2, flowCount(vnetFlowRuleService1));
System.err.println("events :" + listener1.events);
assertEquals("0 rules should exist", 0, flowCount(vnetFlowRuleService2));
providerService1.pushFlowMetrics(VDID1, ImmutableList.of(fe1));
validateEvents(listener1, RULE_UPDATED, RULE_UPDATED);
}
use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class VirtualNetworkFlowRuleManagerTest method purgeFlowRules.
@Test
public void purgeFlowRules() {
FlowRule f1 = addFlowRule(1);
FlowRule f2 = addFlowRule(2);
FlowRule f3 = addFlowRule(3);
assertEquals("3 rules should exist", 3, flowCount(vnetFlowRuleService1));
FlowEntry fe1 = new DefaultFlowEntry(f1);
FlowEntry fe2 = new DefaultFlowEntry(f2);
FlowEntry fe3 = new DefaultFlowEntry(f3);
providerService1.pushFlowMetrics(VDID1, ImmutableList.of(fe1, fe2, fe3));
validateEvents(listener1, RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_ADDED, RULE_ADDED, RULE_ADDED);
vnetFlowRuleService1.purgeFlowRules(VDID1);
assertEquals("0 rule should exist", 0, flowCount(vnetFlowRuleService1));
}
Aggregations