Search in sources :

Example 81 with FlowRule

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

the class RoadmManager method createConnection.

@Override
public FlowId createConnection(DeviceId deviceId, int priority, boolean isPermanent, int timeout, PortNumber inPort, PortNumber outPort, OchSignal ochSignal) {
    checkNotNull(deviceId);
    checkNotNull(inPort);
    checkNotNull(outPort);
    // Creation of selector.
    TrafficSelector selector = DefaultTrafficSelector.builder().add(Criteria.matchInPort(inPort)).add(Criteria.matchOchSignalType(OchSignalType.FIXED_GRID)).add(Criteria.matchLambda(ochSignal)).build();
    // Creation of treatment
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().add(Instructions.modL0Lambda(ochSignal)).add(Instructions.createOutput(outPort)).build();
    FlowRule.Builder flowBuilder = DefaultFlowRule.builder().forDevice(deviceId).fromApp(appId).withPriority(priority).withSelector(selector).withTreatment(treatment);
    if (isPermanent) {
        flowBuilder.makePermanent();
    } else {
        flowBuilder.makeTemporary(timeout);
    }
    FlowRule flowRule = flowBuilder.build();
    flowRuleService.applyFlowRules(flowRule);
    log.info("Created connection from input port {} to output port {}", inPort.toLong(), outPort.toLong());
    return flowRule.id();
}
Also used : TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 82 with FlowRule

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

Example 83 with FlowRule

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

the class VirtualNetworkFlowRuleManagerTest method removeByAppId.

@Test
public void removeByAppId() {
    FlowRule f1 = flowRule(1, 1);
    FlowRule f2 = flowRule(2, 2);
    vnetFlowRuleService1.applyFlowRules(f1, f2);
    vnetFlowRuleService1.removeFlowRulesById(appId);
    // only check that we are in pending remove. Events and actual remove state will
    // be set by flowRemoved call.
    validateState(ImmutableMap.of(f1, FlowEntry.FlowEntryState.PENDING_REMOVE, f2, FlowEntry.FlowEntryState.PENDING_REMOVE));
}
Also used : DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) Test(org.junit.Test)

Example 84 with FlowRule

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

the class VirtualNetworkFlowRuleManagerTest 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(vnetFlowRuleService1.getFlowEntries(DID1)).isEmpty());
    vnetFlowRuleService1.applyFlowRules(r1, r2, r3);
    assertEquals("3 rules should exist", 3, flowCount(vnetFlowRuleService1));
    assertTrue("Entries should be pending add.", validateState(ImmutableMap.of(r1, FlowEntry.FlowEntryState.PENDING_ADD, r2, FlowEntry.FlowEntryState.PENDING_ADD, r3, FlowEntry.FlowEntryState.PENDING_ADD)));
}
Also used : DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) Test(org.junit.Test)

Example 85 with FlowRule

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

Aggregations

FlowRule (org.onosproject.net.flow.FlowRule)351 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)226 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)207 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)207 TrafficSelector (org.onosproject.net.flow.TrafficSelector)174 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)174 Test (org.junit.Test)133 FlowRuleIntent (org.onosproject.net.intent.FlowRuleIntent)90 Intent (org.onosproject.net.intent.Intent)88 DeviceId (org.onosproject.net.DeviceId)87 List (java.util.List)86 Collection (java.util.Collection)68 Collectors (java.util.stream.Collectors)68 CoreService (org.onosproject.core.CoreService)66 VlanId (org.onlab.packet.VlanId)65 VlanIdCriterion (org.onosproject.net.flow.criteria.VlanIdCriterion)61 Collections (java.util.Collections)60 FlowEntry (org.onosproject.net.flow.FlowEntry)59 MplsCriterion (org.onosproject.net.flow.criteria.MplsCriterion)56 ArrayList (java.util.ArrayList)54