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();
}
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));
}
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));
}
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)));
}
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);
}
Aggregations