Search in sources :

Example 6 with FlowEntry

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

the class FlowRuleManagerTest method flowMissingRemove.

/*
     * Tests whether a rule that was marked for removal but no flowRemoved was received
     * is indeed removed at the next stats update.
     */
@Test
public void flowMissingRemove() {
    FlowRule f1 = flowRule(1, 1);
    FlowRule f2 = flowRule(2, 2);
    FlowRule f3 = flowRule(3, 3);
    // FlowRule updatedF1 = flowRule(f1, FlowRuleState.ADDED);
    // FlowRule updatedF2 = flowRule(f2, FlowRuleState.ADDED);
    FlowEntry fe1 = new DefaultFlowEntry(f1);
    FlowEntry fe2 = new DefaultFlowEntry(f2);
    mgr.applyFlowRules(f1, f2, f3);
    mgr.removeFlowRules(f3);
    providerService.pushFlowMetrics(DID, Lists.newArrayList(fe1, fe2));
    validateEvents(RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_REMOVE_REQUESTED, RULE_ADDED, RULE_ADDED, RULE_REMOVED);
}
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 7 with FlowEntry

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

the class FlowRuleManagerTest method getFlowEntries.

@Test
public void getFlowEntries() {
    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());
    providerService.pushFlowMetrics(DID, ImmutableList.of(fe1, fe2));
    validateEvents(RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_ADDED, RULE_ADDED);
    addFlowRule(1);
    System.err.println("events :" + listener.events);
    assertEquals("should still be 2 rules", 2, flowCount());
    providerService.pushFlowMetrics(DID, ImmutableList.of(fe1));
    validateEvents(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 8 with FlowEntry

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

the class FlowRuleManagerTest method flowMetrics.

@Test
public void flowMetrics() {
    FlowRule f1 = flowRule(1, 1);
    FlowRule f2 = flowRule(2, 2);
    FlowRule f3 = flowRule(3, 3);
    mgr.applyFlowRules(f1, f2, f3);
    FlowEntry fe1 = new DefaultFlowEntry(f1);
    FlowEntry fe2 = new DefaultFlowEntry(f2);
    // FlowRule updatedF1 = flowRule(f1, FlowRuleState.ADDED);
    // FlowRule updatedF2 = flowRule(f2, FlowRuleState.ADDED);
    providerService.pushFlowMetrics(DID, Lists.newArrayList(fe1, fe2));
    assertTrue("Entries should be added.", validateState(ImmutableMap.of(f1, FlowEntryState.ADDED, f2, FlowEntryState.ADDED, f3, FlowEntryState.PENDING_ADD)));
    validateEvents(RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_ADDED, RULE_ADDED, RULE_ADD_REQUESTED);
}
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 9 with FlowEntry

use of org.onosproject.net.flow.FlowEntry 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 10 with FlowEntry

use of org.onosproject.net.flow.FlowEntry 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)

Aggregations

FlowEntry (org.onosproject.net.flow.FlowEntry)122 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)26 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 Instruction (org.onosproject.net.flow.instructions.Instruction)16 TrafficSelector (org.onosproject.net.flow.TrafficSelector)15 List (java.util.List)14 DeviceService (org.onosproject.net.device.DeviceService)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