use of org.onosproject.net.flow.criteria.PortCriterion in project onos by opennetworkinglab.
the class DefaultCheckLoop method processOneOutputInstruction.
/**
* Process one output instruction.
*
* Params are passed from processOneInstruction directly,
* and obey the same rules.
*
* @param instOne the instruction to be processed
* @param currentDeviceId id of the device we are now in
* @param initPkt the packet before being copied
* @param matchedPkt the packet which matched the flow entry,
* to which this instruction belongs
* @param isFindLoop indicate if it is invoked by findLoop method
* @param firstEntry the flow entry from which the packet is generated
* @return true, if a loop is discovered;
* false, 1. invoked by matchDeviceFlows method, and detected no loop;
* 2. invoked by findLoop method
*/
private boolean processOneOutputInstruction(Instruction instOne, DeviceId currentDeviceId, TsLoopPacket initPkt, TsLoopPacket matchedPkt, boolean isFindLoop, FlowEntry firstEntry) {
OutputInstruction instOutput = (OutputInstruction) instOne;
PortNumber instPort = instOutput.port();
if (!instPort.isLogical()) {
// single OUTPUT - NIC or normal port
Set<Link> dstLink = tsGetEgressLinks(new ConnectPoint(currentDeviceId, instPort));
if (!dstLink.isEmpty()) {
// TODO - now, just deal with the first destination.
// will there be more destinations?
Link dstThisLink = dstLink.iterator().next();
ConnectPoint dstPoint = dstThisLink.dst();
// check output to devices only (output to a host is normal)
if (isDevice(dstPoint)) {
PortCriterion oldInPort = updatePktInportPerHop(matchedPkt, dstPoint);
matchedPkt.pushPathLink(dstThisLink);
TsLoopPacket newNewPkt = matchedPkt.copyPacketMatch();
boolean loopFound = matchDeviceFlows(dstPoint.deviceId(), newNewPkt);
if (isFindLoop) {
if (loopFound) {
loops.add(newNewPkt);
updateExcludeDeviceSet(newNewPkt);
}
matchedPkt.resetLinkFlow(firstEntry);
} else {
if (loopFound) {
initPkt.handInLoopMatch(newNewPkt);
return true;
}
matchedPkt.popPathLink();
}
restorePktInportPerHop(matchedPkt, oldInPort);
}
} else {
if (!isFindLoop) {
// TODO - NEED
log.warn("no link connecting at device {}, port {}", currentDeviceId, instPort);
}
}
} else if (instPort.equals(PortNumber.IN_PORT)) {
// TODO - in the future,
// we may need to resolve this condition 1
log.warn("can not handle {} port now.", PortNumber.IN_PORT);
} else if (instPort.equals(PortNumber.NORMAL) || instPort.equals(PortNumber.FLOOD) || instPort.equals(PortNumber.ALL)) {
// TODO - in the future,
// we may need to resolve this condition 2
log.warn("can not handle {}/{}/{} now.", PortNumber.NORMAL, PortNumber.FLOOD, PortNumber.ALL);
}
return false;
}
use of org.onosproject.net.flow.criteria.PortCriterion in project onos by opennetworkinglab.
the class TsLoopPacket method copyPacketMatch.
/**
* Creates and returns a new packet instance with the copied match fields.
*
* With hard-copied match fields, references to path flows and path links.
*
* @return new loop packet instance with the copied match fields
*/
public TsLoopPacket copyPacketMatch() {
TsLoopPacket newOne = new TsLoopPacket();
newOne.pathFlow = this.pathFlow;
newOne.pathLink = this.pathLink;
Map<Criterion.Type, Criterion> m = newOne.match;
for (Map.Entry<Criterion.Type, Criterion> entry : this.match.entrySet()) {
Criterion.Type k = entry.getKey();
Criterion v = entry.getValue();
switch(k) {
case IN_PORT:
m.put(k, matchInPort(((PortCriterion) v).port()));
break;
case // At present, not support Ethernet mask (ONOS?)
ETH_SRC:
m.put(k, matchEthSrc(((EthCriterion) v).mac()));
break;
case // At present, not support Ethernet mask (ONOS?)
ETH_DST:
m.put(k, matchEthDst(((EthCriterion) v).mac()));
break;
case ETH_TYPE:
m.put(k, matchEthType(((EthTypeCriterion) v).ethType()));
break;
case // At present, not support VLAN mask (ONOS?)
VLAN_VID:
m.put(k, matchVlanId(((VlanIdCriterion) v).vlanId()));
break;
case VLAN_PCP:
m.put(k, matchVlanPcp(((VlanPcpCriterion) v).priority()));
break;
case IPV4_SRC:
m.put(k, matchIPSrc(((IPCriterion) v).ip()));
break;
case IPV4_DST:
m.put(k, matchIPDst(((IPCriterion) v).ip()));
break;
case IP_PROTO:
m.put(k, matchIPProtocol(((IPProtocolCriterion) v).protocol()));
break;
case // can't be supported by now
IP_DSCP:
m.put(k, matchIPDscp(((IPDscpCriterion) v).ipDscp()));
break;
case // can't be supported by now
IP_ECN:
m.put(k, matchIPEcn(((IPEcnCriterion) v).ipEcn()));
break;
case TCP_SRC:
m.put(k, matchTcpSrc(((TcpPortCriterion) v).tcpPort()));
break;
case TCP_DST:
m.put(k, matchTcpDst(((TcpPortCriterion) v).tcpPort()));
break;
case UDP_SRC:
m.put(k, matchUdpSrc(((UdpPortCriterion) v).udpPort()));
break;
case UDP_DST:
m.put(k, matchUdpDst(((UdpPortCriterion) v).udpPort()));
break;
default:
// can't be supported by OF1.0
log.debug("{} can't be supported by OF1.0", k);
break;
}
}
return newOne;
}
use of org.onosproject.net.flow.criteria.PortCriterion in project onos by opennetworkinglab.
the class LinkCollectionIntentCompilerTest method singleHopNonTrivialForMp.
/**
* We test the proper compilation of mp2sp with
* selector, treatment, filtered
* points and 1 hop.
*/
@Test
public void singleHopNonTrivialForMp() {
intent = LinkCollectionIntent.builder().appId(APP_ID).selector(ipPrefixSelector).treatment(ethDstTreatment).links(ImmutableSet.of()).filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p10, vlan100Selector), new FilteredConnectPoint(d1p11, mpls100Selector))).filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p0, vlan200Selector))).build();
sut.activate();
List<Intent> compiled = sut.compile(intent, Collections.emptyList());
assertThat(compiled, hasSize(1));
Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
assertThat(rules, hasSize(2));
Collection<FlowRule> rulesS1 = rules.stream().filter(rule -> rule.deviceId().equals(d1p0.deviceId())).collect(Collectors.toSet());
assertThat(rulesS1, hasSize(2));
FlowRule ruleS1 = rulesS1.stream().filter(rule -> {
PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
return inPort.port().equals(d1p10.port());
}).findFirst().get();
assertThat(ruleS1.selector(), Is.is(DefaultTrafficSelector.builder(ipPrefixSelector).matchVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId()).matchInPort(d1p10.port()).build()));
assertThat(ruleS1.treatment(), Is.is(DefaultTrafficTreatment.builder().setEthDst(((ModEtherInstruction) ethDstTreatment.allInstructions().stream().filter(instruction -> instruction instanceof ModEtherInstruction).findFirst().get()).mac()).setVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId()).setOutput(d1p0.port()).build()));
ruleS1 = rulesS1.stream().filter(rule -> {
PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
return inPort.port().equals(d1p11.port());
}).findFirst().get();
assertThat(ruleS1.selector(), Is.is(DefaultTrafficSelector.builder(ipPrefixSelector).matchMplsLabel(((MplsCriterion) mpls100Selector.getCriterion(MPLS_LABEL)).label()).matchInPort(d1p11.port()).build()));
assertThat(ruleS1.treatment(), Is.is(DefaultTrafficTreatment.builder().setEthDst(((ModEtherInstruction) ethDstTreatment.allInstructions().stream().filter(instruction -> instruction instanceof ModEtherInstruction).findFirst().get()).mac()).popMpls(IPV4.ethType()).pushVlan().setVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId()).setOutput(d1p0.port()).build()));
sut.deactivate();
}
use of org.onosproject.net.flow.criteria.PortCriterion in project onos by opennetworkinglab.
the class LinkCollectionIntentCompilerTest method singleHopTestFilteredForSp.
/**
* We test the proper compilation of sp2mp with
* trivial selector, trivial treatment and 1 hop.
*/
@Test
public void singleHopTestFilteredForSp() {
intent = LinkCollectionIntent.builder().appId(APP_ID).selector(selector).treatment(treatment).applyTreatmentOnEgress(true).links(ImmutableSet.of()).filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p10, vlan100Selector), new FilteredConnectPoint(d1p11, mpls80Selector))).filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p0, vlan200Selector))).build();
sut.activate();
List<Intent> compiled = sut.compile(intent, Collections.emptyList());
assertThat(compiled, hasSize(1));
Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
assertThat(rules, hasSize(1));
Collection<FlowRule> rulesS1 = rules.stream().filter(rule -> rule.deviceId().equals(d1p0.deviceId())).collect(Collectors.toSet());
assertThat(rulesS1, hasSize(1));
FlowRule ruleS1 = rulesS1.stream().filter(rule -> {
PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
return inPort.port().equals(d1p0.port());
}).findFirst().get();
assertThat(ruleS1.selector(), Is.is(DefaultTrafficSelector.builder(vlan200Selector).matchInPort(d1p0.port()).build()));
assertThat(ruleS1.treatment(), Is.is(DefaultTrafficTreatment.builder().setVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId()).setOutput(d1p10.port()).popVlan().pushMpls().setMpls(((MplsCriterion) mpls80Selector.getCriterion(MPLS_LABEL)).label()).setOutput(d1p11.port()).build()));
sut.deactivate();
}
use of org.onosproject.net.flow.criteria.PortCriterion in project onos by opennetworkinglab.
the class LinkCollectionIntentCompilerTest method singleHopTestFilteredForMp.
/**
* We test the proper compilation of mp2sp with
* trivial selector, trivial treatment, filtered
* points and 1 hop.
*/
@Test
public void singleHopTestFilteredForMp() {
intent = LinkCollectionIntent.builder().appId(APP_ID).selector(selector).treatment(treatment).links(ImmutableSet.of()).filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p10, vlan100Selector), new FilteredConnectPoint(d1p11, mpls69Selector))).filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p0, vlan200Selector))).build();
sut.activate();
List<Intent> compiled = sut.compile(intent, Collections.emptyList());
assertThat(compiled, hasSize(1));
Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
assertThat(rules, hasSize(2));
Collection<FlowRule> rulesS1 = rules.stream().filter(rule -> rule.deviceId().equals(d1p0.deviceId())).collect(Collectors.toSet());
assertThat(rulesS1, hasSize(2));
FlowRule ruleS1 = rulesS1.stream().filter(rule -> {
PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
return inPort.port().equals(d1p10.port());
}).findFirst().get();
assertThat(ruleS1.selector(), Is.is(DefaultTrafficSelector.builder(vlan100Selector).matchInPort(d1p10.port()).build()));
assertThat(ruleS1.treatment(), Is.is(DefaultTrafficTreatment.builder().setVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId()).setOutput(d1p0.port()).build()));
ruleS1 = rulesS1.stream().filter(rule -> {
PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
return inPort.port().equals(d1p11.port());
}).findFirst().get();
assertThat(ruleS1.selector(), Is.is(DefaultTrafficSelector.builder(mpls69Selector).matchInPort(d1p11.port()).build()));
assertThat(ruleS1.treatment(), Is.is(DefaultTrafficTreatment.builder().popMpls(IPV4.ethType()).pushVlan().setVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId()).setOutput(d1p0.port()).build()));
sut.deactivate();
}
Aggregations