use of org.onosproject.net.flow.criteria.PortCriterion in project onos by opennetworkinglab.
the class PicaPipeline 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 p;
if (!filt.key().equals(Criteria.dummy()) && filt.key().type() == Criterion.Type.IN_PORT) {
p = (PortCriterion) filt.key();
} else {
log.warn("No key defined in filtering objective from app: {}. Not" + "processing filtering objective", applicationId);
fail(filt, ObjectiveError.UNKNOWN);
return;
}
EthCriterion e = null;
VlanIdCriterion v = null;
Collection<IPCriterion> ips = new ArrayList<IPCriterion>();
// 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) {
e = (EthCriterion) c;
} else if (c.type() == Criterion.Type.VLAN_VID) {
v = (VlanIdCriterion) c;
} else if (c.type() == Criterion.Type.IPV4_DST) {
ips.add((IPCriterion) c);
} else {
log.error("Unsupported filter {}", c);
fail(filt, ObjectiveError.UNSUPPORTED);
return;
}
}
if (v == null || e == null) {
log.warn("Pica Pipeline ETH_DST and/or VLAN_ID not specified");
fail(filt, ObjectiveError.BADPARAMS);
return;
}
// cache for later use
Filter filter = new Filter(p, e, v, ips);
filters.add(filter);
// apply any pending versatile forwarding objectives
for (ForwardingObjective fwd : pendingVersatiles) {
Collection<FlowRule> ret = processVersatilesWithFilters(filter, fwd);
for (FlowRule fr : ret) {
ops.add(fr);
}
}
for (IPCriterion ipaddr : ips) {
log.debug("adding IP filtering rules in ACL table: {}", ipaddr.ip());
TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
selector.matchInPort(p.port());
selector.matchVlanId(v.vlanId());
selector.matchEthDst(e.mac());
selector.matchEthType(Ethernet.TYPE_IPV4);
// router IPs to the controller
selector.matchIPDst(ipaddr.ip());
treatment.setOutput(PortNumber.CONTROLLER);
FlowRule rule = DefaultFlowRule.builder().forDevice(deviceId).withSelector(selector.build()).withTreatment(treatment.build()).withPriority(HIGHEST_PRIORITY).fromApp(applicationId).makePermanent().forTable(ACL_TABLE).build();
ops = ops.add(rule);
}
// 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");
}
}));
}
use of org.onosproject.net.flow.criteria.PortCriterion in project onos by opennetworkinglab.
the class SoftRouterPipeline 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 p;
EthCriterion e = null;
VlanIdCriterion v = null;
if (!filt.key().equals(Criteria.dummy()) && filt.key().type() == Criterion.Type.IN_PORT) {
p = (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 || c.type() == Criterion.Type.ETH_DST_MASKED) {
e = (EthCriterion) c;
} else if (c.type() == Criterion.Type.VLAN_VID) {
v = (VlanIdCriterion) c;
} else {
log.error("Unsupported filter {}", c);
fail(filt, ObjectiveError.UNSUPPORTED);
return;
}
}
if (v == null || e == null) {
log.warn("Soft Router Pipeline ETH_DST and/or VLAN_ID not specified");
fail(filt, ObjectiveError.BADPARAMS);
return;
}
log.debug("Modifying Port/VLAN/MAC filtering rules in filter table: {}/{}/{}", p.port(), v.vlanId(), e.mac());
TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
selector.matchInPort(p.port());
// Multicast MAC
if (e.mask() != null) {
selector.matchEthDstMasked(e.mac(), e.mask());
} else {
selector.matchEthDst(e.mac());
}
selector.matchVlanId(v.vlanId());
if (!v.vlanId().equals(VlanId.NONE)) {
treatment.popVlan();
}
treatment.transition(FIB_TABLE);
FlowRule rule = DefaultFlowRule.builder().forDevice(deviceId).withSelector(selector.build()).withTreatment(treatment.build()).withPriority(DEFAULT_PRIORITY).fromApp(applicationId).makePermanent().forTable(FILTER_TABLE).build();
ops = install ? ops.add(rule) : ops.remove(rule);
// apply filtering flow rules
flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
@Override
public void onSuccess(FlowRuleOperations ops) {
log.info("Applied filtering rules");
pass(filt);
}
@Override
public void onError(FlowRuleOperations ops) {
log.info("Failed to apply filtering rules");
fail(filt, ObjectiveError.FLOWINSTALLATIONFAILED);
}
}));
}
use of org.onosproject.net.flow.criteria.PortCriterion in project onos by opennetworkinglab.
the class DefaultVirtualFlowRuleProvider method extractIngressPoints.
/**
* Extract ingress connect points of the physical network
* from the requested traffic selector.
*
* @param networkId the virtual network identifier
* @param deviceId the virtual device identifier
* @param selector the traffic selector to extract ingress point
* @return the set of ingress connect points of the physical network
*/
private Set<ConnectPoint> extractIngressPoints(NetworkId networkId, DeviceId deviceId, TrafficSelector selector) {
Set<ConnectPoint> ingressPoints = new HashSet<>();
Set<VirtualPort> vPorts = vnService.getVirtualPorts(networkId, deviceId);
PortCriterion portCriterion = ((PortCriterion) selector.getCriterion(Criterion.Type.IN_PORT));
if (portCriterion != null) {
PortNumber vInPortNum = portCriterion.port();
Optional<ConnectPoint> optionalCp = vPorts.stream().filter(v -> v.number().equals(vInPortNum)).map(VirtualPort::realizedBy).findFirst();
if (!optionalCp.isPresent()) {
log.warn("Port {} is not realized yet, in Network {}, Device {}", vInPortNum, networkId, deviceId);
return ingressPoints;
}
ingressPoints.add(optionalCp.get());
} else {
for (VirtualPort vPort : vPorts) {
if (vPort.realizedBy() != null) {
ingressPoints.add(vPort.realizedBy());
} else {
log.warn("Port {} is not realized yet, in Network {}, " + "Device {}", vPort, networkId, deviceId);
}
}
}
return ingressPoints;
}
use of org.onosproject.net.flow.criteria.PortCriterion 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");
}
}));
}
use of org.onosproject.net.flow.criteria.PortCriterion in project onos by opennetworkinglab.
the class FilteringObjectiveTranslator method doTranslate.
@Override
public ObjectiveTranslation doTranslate(FilteringObjective obj) throws FabricPipelinerException {
final ObjectiveTranslation.Builder resultBuilder = ObjectiveTranslation.builder();
if (obj.key() == null || obj.key().type() != Criterion.Type.IN_PORT) {
throw new FabricPipelinerException(format("Unsupported or missing filtering key: key=%s", obj.key()), ObjectiveError.BADPARAMS);
}
if (!isValidSrMetadata(obj)) {
throw new FabricPipelinerException(format("Unsupported metadata configuration: metadata=%s", obj.meta()), ObjectiveError.BADPARAMS);
}
final PortCriterion inPort = (PortCriterion) obj.key();
final VlanIdCriterion outerVlan = (VlanIdCriterion) criterion(obj.conditions(), Criterion.Type.VLAN_VID);
final VlanIdCriterion innerVlan = (VlanIdCriterion) criterion(obj.conditions(), Criterion.Type.INNER_VLAN_VID);
final EthCriterion ethDst = (EthCriterion) criterion(obj.conditions(), Criterion.Type.ETH_DST);
final EthCriterion ethDstMasked = (EthCriterion) criterion(obj.conditions(), Criterion.Type.ETH_DST_MASKED);
ingressPortVlanRule(obj, inPort, outerVlan, innerVlan, resultBuilder);
if (shouldModifyFwdClassifierTable(obj)) {
fwdClassifierRules(obj, inPort, ethDst, ethDstMasked, resultBuilder);
} else {
log.debug("Skipping fwd classifier rules for device {}.", deviceId);
}
return resultBuilder.build();
}
Aggregations