use of org.onosproject.net.Port in project trellis-control by opennetworkinglab.
the class RoutingRulePopulatorTest method testNoMoreEnabledPortCase4.
// Disable port 1 to 3
@Test
public void testNoMoreEnabledPortCase4() throws Exception {
Port port1 = new DefaultPort(dev1, p1, false);
Port port2 = new DefaultPort(dev1, p2, false);
Port port3 = new DefaultPort(dev1, p3, false);
Port port4 = new DefaultPort(dev1, p4, true);
Port port5 = new DefaultPort(dev1, p5, true);
List<Port> ports = Lists.newArrayList(port1, port2, port3, port4, port5);
expect(deviceService.getPorts(anyObject(DeviceId.class))).andReturn(ports).anyTimes();
replay(deviceService);
assertTrue(rrp.noMoreEnabledPort(devId1, v10));
assertTrue(rrp.noMoreEnabledPort(devId1, v20));
assertFalse(rrp.noMoreEnabledPort(devId1, vInt));
}
use of org.onosproject.net.Port in project TFG by mattinelorza.
the class InterpreterImpl method mapOutboundPacket.
/**
* Returns a collection of PI packet operations populated with metadata
* specific for this pipeconf and equivalent to the given ONOS
* OutboundPacket instance.
*
* @param packet ONOS OutboundPacket
* @return collection of PI packet operations
* @throws PiInterpreterException if the packet treatments cannot be
* executed by this pipeline
*/
@Override
public Collection<PiPacketOperation> mapOutboundPacket(OutboundPacket packet) throws PiInterpreterException {
TrafficTreatment treatment = packet.treatment();
// Packet-out in main.p4 supports only setting the output port,
// i.e. we only understand OUTPUT instructions.
List<OutputInstruction> outInstructions = treatment.allInstructions().stream().filter(i -> i.type().equals(OUTPUT)).map(i -> (OutputInstruction) i).collect(toList());
if (treatment.allInstructions().size() != outInstructions.size()) {
// There are other instructions that are not of type OUTPUT.
throw new PiInterpreterException("Treatment not supported: " + treatment);
}
ImmutableList.Builder<PiPacketOperation> builder = ImmutableList.builder();
for (OutputInstruction outInst : outInstructions) {
if (outInst.port().isLogical() && !outInst.port().equals(FLOOD)) {
throw new PiInterpreterException(format("Packet-out on logical port '%s' not supported", outInst.port()));
} else if (outInst.port().equals(FLOOD)) {
// To emulate flooding, we create a packet-out operation for
// each switch port.
final DeviceService deviceService = handler().get(DeviceService.class);
for (Port port : deviceService.getPorts(packet.sendThrough())) {
builder.add(buildPacketOut(packet.data(), port.number().toLong()));
}
} else {
// Create only one packet-out for the given OUTPUT instruction.
builder.add(buildPacketOut(packet.data(), outInst.port().toLong()));
}
}
return builder.build();
}
use of org.onosproject.net.Port in project onos by opennetworkinglab.
the class ServiceApplicationComponent method createOpticalIntent.
/**
* Returns a new optical intent created from the method parameters.
*
* @param ingress ingress description (device/port)
* @param egress egress description (device/port)
* @param key intent key
* @param appId application id. As per Intent class, it cannot be null
*
* @return created intent
*/
protected Intent createOpticalIntent(ConnectPoint ingress, ConnectPoint egress, Key key, ApplicationId appId) {
if (ingress == null || egress == null) {
log.error("Invalid endpoint(s) for optical intent: ingress {}, egress {}", ingress, egress);
return null;
}
DeviceService ds = opticalView(deviceService);
Port srcPort = ds.getPort(ingress.deviceId(), ingress.port());
Port dstPort = ds.getPort(egress.deviceId(), egress.port());
if (srcPort == null || dstPort == null) {
log.error("Invalid port(s) for optical intent: src {}, dst {}", srcPort, dstPort);
return null;
}
OduSignalType signalType = ((OchPort) srcPort).signalType();
return OpticalConnectivityIntent.builder().appId(appId).key(key).src(ingress).dst(egress).signalType(signalType).bidirectional(// TODO Revisit this.
true).build();
}
use of org.onosproject.net.Port in project onos by opennetworkinglab.
the class Ofdpa2Pipeline method processEthDstFilter.
/**
* Allows routed packets with correct destination MAC to be directed
* to unicast routing table, multicast routing table or MPLS forwarding table.
*
* @param portCriterion port on device for which this filter is programmed
* @param ethCriterion dstMac of device for which is filter is programmed
* @param vidCriterion vlan assigned to port, or NONE for untagged
* @param assignedVlan assigned vlan-id for untagged packets
* @param unicastMac some switches require a unicast TMAC flow to be programmed before multicast
* TMAC flow. This MAC address will be used for the unicast TMAC flow.
* This is unused if the filtering objective is a unicast.
* @param applicationId for application programming this filter
* @return stages of flow rules for port-vlan filters
*/
protected List<List<FlowRule>> processEthDstFilter(PortCriterion portCriterion, EthCriterion ethCriterion, VlanIdCriterion vidCriterion, VlanId assignedVlan, MacAddress unicastMac, ApplicationId applicationId) {
// Consider PortNumber.ANY as wildcard. Match ETH_DST only
if (portCriterion != null && PortNumber.ANY.equals(portCriterion.port())) {
return processEthDstOnlyFilter(ethCriterion, applicationId);
}
// Multicast MAC
if (ethCriterion.mask() != null) {
return processMcastEthDstFilter(ethCriterion, assignedVlan, unicastMac, applicationId);
}
// handling untagged packets via assigned VLAN
if (vidCriterion != null && vidCriterion.vlanId() == VlanId.NONE) {
vidCriterion = (VlanIdCriterion) Criteria.matchVlanId(assignedVlan);
}
List<FlowRule> rules = new ArrayList<>();
OfdpaMatchVlanVid ofdpaMatchVlanVid = null;
if (vidCriterion != null && requireVlanExtensions()) {
ofdpaMatchVlanVid = new OfdpaMatchVlanVid(vidCriterion.vlanId());
}
// ofdpa cannot match on ALL portnumber, so we need to use separate
// rules for each port.
List<PortNumber> portnums = new ArrayList<>();
if (portCriterion != null) {
if (PortNumber.ALL.equals(portCriterion.port())) {
for (Port port : deviceService.getPorts(deviceId)) {
if (port.number().toLong() > 0 && port.number().toLong() < OFPP_MAX) {
portnums.add(port.number());
}
}
} else {
portnums.add(portCriterion.port());
}
for (PortNumber pnum : portnums) {
rules.add(buildTmacRuleForIpv4(ethCriterion, vidCriterion, ofdpaMatchVlanVid, applicationId, pnum));
rules.add(buildTmacRuleForMpls(ethCriterion, vidCriterion, ofdpaMatchVlanVid, applicationId, pnum));
rules.add(buildTmacRuleForIpv6(ethCriterion, vidCriterion, ofdpaMatchVlanVid, applicationId, pnum));
}
} else {
rules.add(buildTmacRuleForIpv4(ethCriterion, vidCriterion, ofdpaMatchVlanVid, applicationId, null));
rules.add(buildTmacRuleForMpls(ethCriterion, vidCriterion, ofdpaMatchVlanVid, applicationId, null));
rules.add(buildTmacRuleForIpv6(ethCriterion, vidCriterion, ofdpaMatchVlanVid, applicationId, null));
}
return ImmutableList.of(rules);
}
use of org.onosproject.net.Port in project onos by opennetworkinglab.
the class OvsOfdpaPipeline method processEgress.
/**
* In the OF-DPA 2.0 pipeline, egress forwarding objectives go to the
* egress tables.
* @param fwd the forwarding objective of type 'egress'
* @return a collection of flow rules to be sent to the switch. An empty
* collection may be returned if there is a problem in processing
* the flow rule
*/
@Override
protected Collection<FlowRule> processEgress(ForwardingObjective fwd) {
log.debug("Processing egress forwarding objective:{} in dev:{}", fwd, deviceId);
List<FlowRule> rules = new ArrayList<>();
// Build selector
TrafficSelector.Builder sb = DefaultTrafficSelector.builder();
VlanIdCriterion vlanIdCriterion = (VlanIdCriterion) fwd.selector().getCriterion(Criterion.Type.VLAN_VID);
if (vlanIdCriterion == null) {
log.error("Egress forwarding objective:{} must include vlanId", fwd.id());
fail(fwd, ObjectiveError.BADPARAMS);
return rules;
}
Optional<Instruction> outInstr = fwd.treatment().allInstructions().stream().filter(instruction -> instruction instanceof Instructions.OutputInstruction).findFirst();
if (!outInstr.isPresent()) {
log.error("Egress forwarding objective:{} must include output port", fwd.id());
fail(fwd, ObjectiveError.BADPARAMS);
return rules;
}
PortNumber portNumber = ((Instructions.OutputInstruction) outInstr.get()).port();
sb.matchVlanId(vlanIdCriterion.vlanId());
OfdpaMatchActsetOutput actsetOutput = new OfdpaMatchActsetOutput(portNumber);
sb.extension(actsetOutput, deviceId);
// Build a flow rule for Egress VLAN Flow table
TrafficTreatment.Builder tb = DefaultTrafficTreatment.builder();
tb.transition(UNICAST_ROUTING_TABLE_1);
if (fwd.treatment() != null) {
for (Instruction instr : fwd.treatment().allInstructions()) {
if (instr instanceof L2ModificationInstruction && ((L2ModificationInstruction) instr).subtype() == L2ModificationInstruction.L2SubType.VLAN_ID) {
tb.immediate().add(instr);
}
if (instr instanceof L2ModificationInstruction && ((L2ModificationInstruction) instr).subtype() == L2ModificationInstruction.L2SubType.VLAN_PUSH) {
EthType ethType = ((L2ModificationInstruction.ModVlanHeaderInstruction) instr).ethernetType();
tb.immediate().pushVlan(ethType);
}
}
}
FlowRule.Builder ruleBuilder = DefaultFlowRule.builder().fromApp(fwd.appId()).withPriority(fwd.priority()).forDevice(deviceId).withSelector(sb.build()).withTreatment(tb.build()).makePermanent().forTable(EGRESS_VLAN_FLOW_TABLE_IN_INGRESS);
rules.add(ruleBuilder.build());
return rules;
}
Aggregations