use of org.onosproject.net.flow.criteria.IPCriterion 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.IPCriterion in project onos by opennetworkinglab.
the class DefaultCheckLoop method matchAddIPV4.
// before invoking this, MUST insure EtherType is IPv4.
private boolean matchAddIPV4(TsLoopPacket pkt, Criterion criterion, TsReturn<Boolean> isBigger) {
if (pkt.headerExists(criterion.type())) {
IpPrefix ipFlow = ((IPCriterion) criterion).ip();
IpPrefix ipPkt = ((IPCriterion) pkt.getHeader(criterion.type())).ip();
// attention - the order below is important
if (ipFlow.equals(ipPkt)) {
// shoot
} else if (ipFlow.contains(ipPkt)) {
// shoot, pkt is more exact than flowEntry
} else if (ipPkt.contains(ipFlow)) {
// pkt should be changed to be more exact
pkt.setHeader(criterion);
isBigger.setValue(true);
} else {
// match fail
return false;
}
} else {
// attention the order of criteria in "for" loop
pkt.setHeader(criterion);
isBigger.setValue(true);
}
return true;
}
use of org.onosproject.net.flow.criteria.IPCriterion in project onos by opennetworkinglab.
the class TelemetryVflowListCommand method doExecute.
@Override
protected void doExecute() {
CoreService coreService = get(CoreService.class);
FlowRuleService flowService = get(FlowRuleService.class);
ApplicationId appId = coreService.getAppId(OPENSTACK_TELEMETRY_APP_ID);
List<FlowEntry> flows = Lists.newArrayList(flowService.getFlowEntriesById(appId));
print(FORMAT, "SrcIp", "SrcPort", "DstIp", "DstPort", "Protocol");
for (FlowEntry entry : flows) {
TrafficSelector selector = entry.selector();
IpPrefix srcIp = ((IPCriterion) selector.getCriterion(IPV4_SRC)).ip();
IpPrefix dstIp = ((IPCriterion) selector.getCriterion(IPV4_DST)).ip();
TpPort srcPort = TpPort.tpPort(0);
TpPort dstPort = TpPort.tpPort(0);
String protocolStr = "ANY";
Criterion ipProtocolCriterion = selector.getCriterion(IP_PROTO);
if (ipProtocolCriterion != null) {
short protocol = ((IPProtocolCriterion) selector.getCriterion(IP_PROTO)).protocol();
if (protocol == PROTOCOL_TCP) {
srcPort = ((TcpPortCriterion) selector.getCriterion(TCP_SRC)).tcpPort();
dstPort = ((TcpPortCriterion) selector.getCriterion(TCP_DST)).tcpPort();
protocolStr = TCP;
}
if (protocol == PROTOCOL_UDP) {
srcPort = ((UdpPortCriterion) selector.getCriterion(UDP_SRC)).udpPort();
dstPort = ((UdpPortCriterion) selector.getCriterion(UDP_SRC)).udpPort();
protocolStr = UDP;
}
}
print(FORMAT, srcIp.toString(), srcPort.toString(), dstIp.toString(), dstPort.toString(), protocolStr);
}
}
use of org.onosproject.net.flow.criteria.IPCriterion in project onos by opennetworkinglab.
the class OpenstackTroubleshootManager method checkFlowRule.
/**
* Checks whether flow rules with the given IP and criterion are added or not.
*
* @param ip IP address
* @param ipType IP criterion type (IPV4_DST or IPV4_SRC)
* @return true if the flow rule is added, false otherwise
*/
private boolean checkFlowRule(String ip, Criterion.Type ipType) {
for (FlowEntry entry : flowRuleService.getFlowEntriesById(appId)) {
TrafficSelector selector = entry.selector();
IPCriterion ipCriterion = (IPCriterion) selector.getCriterion(ipType);
if (ipCriterion != null && ip.equals(ipCriterion.ip().address().toString()) && entry.state() == ADDED) {
return true;
}
}
return false;
}
use of org.onosproject.net.flow.criteria.IPCriterion in project onos by opennetworkinglab.
the class AbstractCorsaPipeline method processFilter.
private void processFilter(FilteringObjective filt, boolean install, ApplicationId applicationId) {
// This driver only processes filtering criteria defined with switch
// ports as the key
PortCriterion port;
if (!filt.key().equals(Criteria.dummy()) && filt.key().type() == Criterion.Type.IN_PORT) {
port = (PortCriterion) filt.key();
} else {
log.warn("No key defined in filtering objective from app: {}. Not" + "processing filtering objective", applicationId);
fail(filt, ObjectiveError.UNKNOWN);
return;
}
// convert filtering conditions for switch-intfs into flowrules
FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
for (Criterion c : filt.conditions()) {
if (c.type() == Criterion.Type.ETH_DST) {
EthCriterion eth = (EthCriterion) c;
FlowRule.Builder rule = processEthFiler(filt, eth, port);
rule.forDevice(deviceId).fromApp(applicationId);
ops = install ? ops.add(rule.build()) : ops.remove(rule.build());
} else if (c.type() == Criterion.Type.VLAN_VID) {
VlanIdCriterion vlan = (VlanIdCriterion) c;
FlowRule.Builder rule = processVlanFiler(filt, vlan, port);
rule.forDevice(deviceId).fromApp(applicationId);
ops = install ? ops.add(rule.build()) : ops.remove(rule.build());
} else if (c.type() == Criterion.Type.IPV4_DST) {
IPCriterion ip = (IPCriterion) c;
FlowRule.Builder rule = processIpFilter(filt, ip, port);
rule.forDevice(deviceId).fromApp(applicationId);
ops = install ? ops.add(rule.build()) : ops.remove(rule.build());
} else {
log.warn("Driver does not currently process filtering condition" + " of type: {}", c.type());
fail(filt, ObjectiveError.UNSUPPORTED);
}
}
// apply filtering flow rules
flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
@Override
public void onSuccess(FlowRuleOperations ops) {
pass(filt);
log.info("Applied filtering rules");
}
@Override
public void onError(FlowRuleOperations ops) {
fail(filt, ObjectiveError.FLOWINSTALLATIONFAILED);
log.info("Failed to apply filtering rules");
}
}));
}
Aggregations