use of org.onosproject.net.Lambda in project onos by opennetworkinglab.
the class CriterionCodecTest method matchOchSignal.
/**
* Tests lambda criterion.
*/
@Test
public void matchOchSignal() {
Lambda ochSignal = Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_100GHZ, 4, 8);
Criterion criterion = Criteria.matchLambda(ochSignal);
ObjectNode result = criterionCodec.encode(criterion, context);
assertThat(result, matchesCriterion(criterion));
}
use of org.onosproject.net.Lambda in project onos by opennetworkinglab.
the class IntentCodecTest method intentWithTreatmentSelectorAndConstraints.
/**
* Tests the encoding of an intent with treatment, selector and constraints
* specified.
*/
@Test
public void intentWithTreatmentSelectorAndConstraints() {
ConnectPoint ingress = NetTestTools.connectPoint("ingress", 1);
ConnectPoint egress = NetTestTools.connectPoint("egress", 2);
DeviceId did1 = did("device1");
DeviceId did2 = did("device2");
DeviceId did3 = did("device3");
Lambda ochSignal = Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_100GHZ, 4, 8);
final TrafficSelector selector = DefaultTrafficSelector.builder().matchIPProtocol((byte) 3).matchMplsLabel(MplsLabel.mplsLabel(4)).add(Criteria.matchOchSignalType(OchSignalType.FIXED_GRID)).add(Criteria.matchLambda(ochSignal)).matchEthDst(MacAddress.BROADCAST).matchIPDst(IpPrefix.valueOf("1.2.3.4/24")).build();
final TrafficTreatment treatment = DefaultTrafficTreatment.builder().setMpls(MplsLabel.mplsLabel(44)).setOutput(PortNumber.CONTROLLER).setEthDst(MacAddress.BROADCAST).build();
final List<Constraint> constraints = ImmutableList.of(new BandwidthConstraint(Bandwidth.bps(1.0)), new AnnotationConstraint("key", 33.0), new AsymmetricPathConstraint(), new LatencyConstraint(Duration.ofSeconds(2)), new ObstacleConstraint(did1, did2), new WaypointConstraint(did3));
final PointToPointIntent intent = PointToPointIntent.builder().appId(appId).selector(selector).treatment(treatment).filteredIngressPoint(new FilteredConnectPoint(ingress)).filteredEgressPoint(new FilteredConnectPoint(egress)).constraints(constraints).build();
final JsonCodec<PointToPointIntent> intentCodec = context.codec(PointToPointIntent.class);
assertThat(intentCodec, notNullValue());
final ObjectNode intentJson = intentCodec.encode(intent, context);
assertThat(intentJson, matchesIntent(intent));
}
use of org.onosproject.net.Lambda in project onos by opennetworkinglab.
the class OplinkOpticalUtility method fromFlowRule.
/**
* Transforms a flow FlowRule object to an OplinkCrossConnect object.
* @param behaviour the parent driver handler
* @param rule FlowRule object
* @return cross connect object
*/
public static OplinkCrossConnect fromFlowRule(HandlerBehaviour behaviour, FlowRule rule) {
// TrafficSelector
Set<Criterion> criterions = rule.selector().criteria();
int channel = criterions.stream().filter(c -> c instanceof OchSignalCriterion).map(c -> ((OchSignalCriterion) c).lambda().spacingMultiplier()).findAny().orElse(null);
PortNumber inPort = criterions.stream().filter(c -> c instanceof PortCriterion).map(c -> ((PortCriterion) c).port()).findAny().orElse(null);
// TrafficTreatment
List<Instruction> instructions = rule.treatment().immediate();
PortNumber outPort = instructions.stream().filter(c -> c instanceof Instructions.OutputInstruction).map(c -> ((Instructions.OutputInstruction) c).port()).findAny().orElse(null);
int attenuation = instructions.stream().filter(c -> c instanceof Instructions.ExtensionInstructionWrapper).map(c -> ((Instructions.ExtensionInstructionWrapper) c).extensionInstruction()).filter(c -> c instanceof OplinkAttenuation).map(c -> ((OplinkAttenuation) c).getAttenuation()).findAny().orElse(DEFAULT_ATT);
return new OplinkCrossConnect(inPort, outPort, channel, attenuation);
}
use of org.onosproject.net.Lambda in project onos by opennetworkinglab.
the class FlowRuleCodecTest method codecSigIdCriteriaFlowTest.
/**
* Checks that a rule with a SigId criterion decodes properly.
*
* @throws IOException if the resource cannot be processed
*/
@Test
public void codecSigIdCriteriaFlowTest() throws Exception {
FlowRule rule = getRule("sigid-flow.json");
checkCommonData(rule);
assertThat(rule.selector().criteria().size(), is(1));
Criterion criterion = rule.selector().criteria().iterator().next();
assertThat(criterion.type(), is(Criterion.Type.OCH_SIGID));
Lambda lambda = ((OchSignalCriterion) criterion).lambda();
assertThat(lambda, instanceOf(OchSignal.class));
OchSignal ochSignal = (OchSignal) lambda;
assertThat(ochSignal.spacingMultiplier(), is(3));
assertThat(ochSignal.slotGranularity(), is(4));
assertThat(ochSignal.gridType(), is(GridType.CWDM));
assertThat(ochSignal.channelSpacing(), is(ChannelSpacing.CHL_25GHZ));
}
use of org.onosproject.net.Lambda in project onos by opennetworkinglab.
the class OplinkOpticalUtility method toFlowRule.
/**
* Finds the FlowRule from flow rule store by the given ports and channel.
* Returns an extra flow to remove the flow by ONOS if not found.
* @param behaviour the parent driver handler
* @param inPort the input port
* @param outPort the output port
* @param channel the specified channel
* @return the flow rule
*/
public static FlowRule toFlowRule(HandlerBehaviour behaviour, PortNumber inPort, PortNumber outPort, Integer channel) {
FlowRuleService service = behaviour.handler().get(FlowRuleService.class);
Iterable<FlowEntry> entries = service.getFlowEntries(behaviour.data().deviceId());
// Try to Find the flow from flow rule store.
for (FlowEntry entry : entries) {
Set<Criterion> criterions = entry.selector().criteria();
// input port
PortNumber ip = criterions.stream().filter(c -> c instanceof PortCriterion).map(c -> ((PortCriterion) c).port()).findAny().orElse(null);
// channel
Integer ch = criterions.stream().filter(c -> c instanceof OchSignalCriterion).map(c -> ((OchSignalCriterion) c).lambda().spacingMultiplier()).findAny().orElse(null);
// output port
PortNumber op = entry.treatment().immediate().stream().filter(c -> c instanceof Instructions.OutputInstruction).map(c -> ((Instructions.OutputInstruction) c).port()).findAny().orElse(null);
if (inPort.equals(ip) && channel.equals(ch) && outPort.equals(op)) {
// Find the flow.
return entry;
}
}
// Cannot find the flow from store. So report an extra flow to remove the flow by ONOS.
TrafficSelector selector = DefaultTrafficSelector.builder().matchInPort(inPort).add(Criteria.matchOchSignalType(OchSignalType.FIXED_GRID)).add(Criteria.matchLambda(Lambda.ochSignal(GRID_TYPE, CHANNEL_SPACING, channel, SLOT_GRANULARITY))).build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(outPort).build();
return DefaultFlowRule.builder().forDevice(behaviour.data().deviceId()).withSelector(selector).withTreatment(treatment).withPriority(DEFAULT_PRIORITY).makePermanent().fromApp(behaviour.handler().get(CoreService.class).getAppId(DEFAULT_APP)).build();
}
Aggregations