Search in sources :

Example 16 with FlowRule

use of org.onosproject.net.flow.FlowRule in project onos by opennetworkinglab.

the class FlowRuleManagerTest method validateState.

private boolean validateState(Map<FlowRule, FlowEntryState> expected) {
    Map<FlowRule, FlowEntryState> expectedToCheck = new HashMap<>(expected);
    Iterable<FlowEntry> rules = service.getFlowEntries(DID);
    for (FlowEntry f : rules) {
        assertTrue("Unexpected FlowRule " + f, expectedToCheck.containsKey(f));
        assertEquals("FlowEntry" + f, expectedToCheck.get(f), f.state());
        expectedToCheck.remove(f);
    }
    assertEquals(Collections.emptySet(), expectedToCheck.entrySet());
    return true;
}
Also used : HashMap(java.util.HashMap) FlowEntryState(org.onosproject.net.flow.FlowEntry.FlowEntryState) 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)

Example 17 with FlowRule

use of org.onosproject.net.flow.FlowRule in project onos by opennetworkinglab.

the class FlowRuleManagerTest method getFlowEntry.

@Test
public void getFlowEntry() {
    assertTrue("store should be empty", Sets.newHashSet(service.getFlowEntries(DID)).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());
    FlowEntry actual1 = service.getFlowEntry(f1);
    FlowEntry actual2 = service.getFlowEntry(f2);
    assertEquals(fe1, actual1);
    assertEquals(fe2, actual2);
}
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 18 with FlowRule

use of org.onosproject.net.flow.FlowRule in project onos by opennetworkinglab.

the class FlowRuleManagerTest method applyFlowRules.

@Test
public void applyFlowRules() {
    FlowRule r1 = flowRule(1, 1);
    FlowRule r2 = flowRule(2, 2);
    FlowRule r3 = flowRule(3, 3);
    assertTrue("store should be empty", Sets.newHashSet(service.getFlowEntries(DID)).isEmpty());
    mgr.applyFlowRules(r1, r2, r3);
    assertEquals("3 rules should exist", 3, flowCount());
    assertTrue("Entries should be pending add.", validateState(ImmutableMap.of(r1, FlowEntryState.PENDING_ADD, r2, FlowEntryState.PENDING_ADD, r3, FlowEntryState.PENDING_ADD)));
}
Also used : DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) Test(org.junit.Test)

Example 19 with FlowRule

use of org.onosproject.net.flow.FlowRule in project onos by opennetworkinglab.

the class FlowRuleManagerTest method fallbackBasics.

@Test
public void fallbackBasics() {
    FlowRule f1 = flowRule(FOO_DID, 1, 1);
    flowRules.clear();
    mgr.applyFlowRules(f1);
    assertTrue("flow rule not applied", flowRules.contains(f1));
    flowRules.clear();
    mgr.removeFlowRules(f1);
    assertTrue("flow rule not removed", flowRules.contains(f1));
}
Also used : DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) Test(org.junit.Test)

Example 20 with FlowRule

use of org.onosproject.net.flow.FlowRule in project onos by opennetworkinglab.

the class FlowRuleManagerTest method fallbackPoll.

@Test
public void fallbackPoll() {
    FlowRuleDriverProvider fallback = (FlowRuleDriverProvider) mgr.defaultProvider();
    FlowRule f1 = flowRule(FOO_DID, 1, 1);
    mgr.applyFlowRules(f1);
    FlowEntry fe = mgr.getFlowEntries(FOO_DID).iterator().next();
    assertEquals("incorrect state", FlowEntryState.PENDING_ADD, fe.state());
    fallback.init(fallback.providerService, mgr.deviceService, mgr.mastershipService, 1);
    TestTools.assertAfter(2000, () -> {
        FlowEntry e = mgr.getFlowEntries(FOO_DID).iterator().next();
        assertEquals("incorrect state", FlowEntryState.ADDED, e.state());
    });
}
Also used : 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

FlowRule (org.onosproject.net.flow.FlowRule)432 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)279 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)226 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)225 TrafficSelector (org.onosproject.net.flow.TrafficSelector)193 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)189 Test (org.junit.Test)173 List (java.util.List)101 DeviceId (org.onosproject.net.DeviceId)101 FlowRuleIntent (org.onosproject.net.intent.FlowRuleIntent)90 Intent (org.onosproject.net.intent.Intent)88 Collection (java.util.Collection)75 Collectors (java.util.stream.Collectors)75 CoreService (org.onosproject.core.CoreService)72 Collections (java.util.Collections)70 VlanId (org.onlab.packet.VlanId)65 FlowEntry (org.onosproject.net.flow.FlowEntry)63 VlanIdCriterion (org.onosproject.net.flow.criteria.VlanIdCriterion)61 PortNumber (org.onosproject.net.PortNumber)57 ArrayList (java.util.ArrayList)56