Search in sources :

Example 31 with FlowEntry

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;
}
Also used : IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) FlowEntry(org.onosproject.net.flow.FlowEntry)

Example 32 with FlowEntry

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;
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) DeviceId(org.onosproject.net.DeviceId) ArrayList(java.util.ArrayList) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) Objective(org.onosproject.net.flowobjective.Objective) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) FlowEntry(org.onosproject.net.flow.FlowEntry) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective)

Example 33 with FlowEntry

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;
}
Also used : ArrayList(java.util.ArrayList) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) FlowEntry(org.onosproject.net.flow.FlowEntry)

Example 34 with FlowEntry

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);
}
Also used : DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) FlowEntry(org.onosproject.net.flow.FlowEntry) StoredFlowEntry(org.onosproject.net.flow.StoredFlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) Test(org.junit.Test)

Example 35 with FlowEntry

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));
}
Also used : DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) FlowEntry(org.onosproject.net.flow.FlowEntry) StoredFlowEntry(org.onosproject.net.flow.StoredFlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) Test(org.junit.Test)

Aggregations

FlowEntry (org.onosproject.net.flow.FlowEntry)123 DefaultFlowEntry (org.onosproject.net.flow.DefaultFlowEntry)61 FlowRule (org.onosproject.net.flow.FlowRule)51 Test (org.junit.Test)31 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)31 FlowRuleService (org.onosproject.net.flow.FlowRuleService)27 ArrayList (java.util.ArrayList)24 StoredFlowEntry (org.onosproject.net.flow.StoredFlowEntry)23 DeviceId (org.onosproject.net.DeviceId)20 Device (org.onosproject.net.Device)19 PortNumber (org.onosproject.net.PortNumber)17 TrafficSelector (org.onosproject.net.flow.TrafficSelector)16 Instruction (org.onosproject.net.flow.instructions.Instruction)16 DeviceService (org.onosproject.net.device.DeviceService)15 List (java.util.List)14 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)13 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)13 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)12 HashSet (java.util.HashSet)12 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)11