use of org.onosproject.net.flow.criteria.IPCriterion in project fabric-tna by stratum.
the class ForwardingObjectiveTranslator method ipv4RoutingRule.
private void ipv4RoutingRule(ForwardingObjective obj, Set<Criterion> criteriaWithMeta, ObjectiveTranslation.Builder resultBuilder) throws FabricPipelinerException {
final IPCriterion ipDstCriterion = (IPCriterion) criterionNotNull(criteriaWithMeta, Criterion.Type.IPV4_DST);
if (ipDstCriterion.ip().prefixLength() == 0) {
defaultIpv4Route(obj, resultBuilder);
return;
}
final TrafficSelector selector = DefaultTrafficSelector.builder().add(ipDstCriterion).build();
resultBuilder.addFlowRule(flowRule(obj, P4InfoConstants.FABRIC_INGRESS_FORWARDING_ROUTING_V4, selector));
}
use of org.onosproject.net.flow.criteria.IPCriterion in project fabric-tna by stratum.
the class FabricIntProgrammable method buildCollectorSelector.
private TrafficSelector buildCollectorSelector(Set<Criterion> criteria) {
TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
// We always match packets with valid IPv4 header
PiCriterion.Builder piBuilder = PiCriterion.builder().matchExact(P4InfoConstants.HDR_IPV4_VALID, 1);
for (Criterion criterion : criteria) {
switch(criterion.type()) {
case IP_PROTO:
builder.matchIPProtocol((byte) ((IPProtocolCriterion) criterion).protocol());
break;
case IPV4_SRC:
builder.matchIPSrc(((IPCriterion) criterion).ip());
break;
case IPV4_DST:
builder.matchIPDst(((IPCriterion) criterion).ip());
break;
case TCP_SRC:
// TODO: Match a range of TCP port
piBuilder.matchRange(P4InfoConstants.HDR_L4_SPORT, ((TcpPortCriterion) criterion).tcpPort().toInt(), ((TcpPortCriterion) criterion).tcpPort().toInt());
break;
case UDP_SRC:
// TODO: Match a range of UDP port
piBuilder.matchRange(P4InfoConstants.HDR_L4_SPORT, ((UdpPortCriterion) criterion).udpPort().toInt(), ((UdpPortCriterion) criterion).udpPort().toInt());
break;
case TCP_DST:
// TODO: Match a range of TCP port
piBuilder.matchRange(P4InfoConstants.HDR_L4_DPORT, ((TcpPortCriterion) criterion).tcpPort().toInt(), ((TcpPortCriterion) criterion).tcpPort().toInt());
break;
case UDP_DST:
// TODO: Match a range of UDP port
piBuilder.matchRange(P4InfoConstants.HDR_L4_DPORT, ((UdpPortCriterion) criterion).udpPort().toInt(), ((UdpPortCriterion) criterion).udpPort().toInt());
break;
default:
log.warn("Unsupported criterion type: {}", criterion.type());
}
}
return builder.matchPi(piBuilder.build()).build();
}
use of org.onosproject.net.flow.criteria.IPCriterion in project onos by opennetworkinglab.
the class FlowRuleJuniperImpl method manageRules.
private Collection<FlowRule> manageRules(Collection<FlowRule> rules, OperationType type) {
DeviceId deviceId = this.data().deviceId();
log.debug("{} flow entries to NETCONF device {}", type, deviceId);
NetconfSession session = lookupNetconfSession(deviceId);
Collection<FlowRule> managedRules = new HashSet<>();
for (FlowRule flowRule : rules) {
Optional<IPCriterion> ipCriterion = getIpCriterion(flowRule);
if (!ipCriterion.isPresent()) {
log.error("Currently not supported: IPv4 destination match must be used");
continue;
}
Optional<OutputInstruction> output = getOutput(flowRule);
if (!output.isPresent()) {
log.error("Currently not supported: the output action is needed");
continue;
}
getStaticRoute(deviceId, ipCriterion.get(), output.get(), flowRule.priority()).ifPresent(staticRoute -> {
// If the static route is not local, the driver tries to install
if (!staticRoute.isLocalRoute()) {
// FlowRule as installed.
if (editRoute(session, type, staticRoute)) {
managedRules.add(flowRule);
}
// If static route are local, they are not installed
// because are not required. Directly connected routes
// are automatically forwarded.
} else {
managedRules.add(flowRule);
}
});
}
return rules;
}
use of org.onosproject.net.flow.criteria.IPCriterion in project onos by opennetworkinglab.
the class FlowRuleJuniperImpl method getStaticRoute.
/**
* Helper method to convert FlowRule into an abstraction of static route
* {@link StaticRoute}.
*
* @param devId the device id
* @param criteria the IP destination criteria
* @param output the output instruction
* @return optional of Static Route
*/
private Optional<StaticRoute> getStaticRoute(DeviceId devId, IPCriterion criteria, OutputInstruction output, int priority) {
DeviceService deviceService = this.handler().get(DeviceService.class);
Collection<Port> ports = deviceService.getPorts(devId);
Optional<Port> port = ports.stream().filter(x -> x.number().equals(output.port())).findAny();
if (!port.isPresent()) {
log.error("The port {} does not exist in the device", output.port());
return Optional.empty();
}
// Find if the route refers to a local interface.
Optional<Port> local = deviceService.getPorts(devId).stream().filter(this::isIp).filter(p -> criteria.ip().getIp4Prefix().contains(Ip4Address.valueOf(p.annotations().value(JuniperUtils.AK_IP)))).findAny();
if (local.isPresent()) {
return Optional.of(new StaticRoute(criteria.ip().getIp4Prefix(), criteria.ip().getIp4Prefix().address(), true, priority));
}
Optional<Ip4Address> nextHop = findIpDst(devId, port.get());
if (nextHop.isPresent()) {
return Optional.of(new StaticRoute(criteria.ip().getIp4Prefix(), nextHop.get(), false, priority));
} else {
log.error("The destination interface has not an IP {}", port.get());
return Optional.empty();
}
}
use of org.onosproject.net.flow.criteria.IPCriterion in project onos by opennetworkinglab.
the class FlowRuleJuniperImpl method getFlowEntries.
@Override
public Collection<FlowEntry> getFlowEntries() {
DeviceId devId = checkNotNull(this.data().deviceId());
NetconfSession session = lookupNetconfSession(devId);
if (session == null) {
return Collections.emptyList();
}
// Installed static routes
String reply;
try {
reply = session.get(routingTableBuilder());
} catch (NetconfException e) {
throw new IllegalStateException(new NetconfException("Failed to retrieve configuration.", e));
}
Collection<StaticRoute> devicesStaticRoutes = JuniperUtils.parseRoutingTable(loadXmlString(reply));
// Expected FlowEntries installed
FlowRuleService flowRuleService = this.handler().get(FlowRuleService.class);
Iterable<FlowEntry> flowEntries = flowRuleService.getFlowEntries(devId);
Collection<FlowEntry> installedRules = new HashSet<>();
flowEntries.forEach(flowEntry -> {
Optional<IPCriterion> ipCriterion = getIpCriterion(flowEntry);
if (!ipCriterion.isPresent()) {
return;
}
Optional<OutputInstruction> output = getOutput(flowEntry);
if (!output.isPresent()) {
return;
}
// convert FlowRule into static route
getStaticRoute(devId, ipCriterion.get(), output.get(), flowEntry.priority()).ifPresent(staticRoute -> {
if (staticRoute.isLocalRoute()) {
// if the FlowRule is in PENDING_REMOVE or REMOVED, it is not reported.
if (flowEntry.state() == PENDING_REMOVE || flowEntry.state() == REMOVED) {
devicesStaticRoutes.remove(staticRoute);
} else {
// FlowRule is reported installed
installedRules.add(flowEntry);
devicesStaticRoutes.remove(staticRoute);
}
} else {
// if the route is found in the device, the FlowRule is reported installed.
if (devicesStaticRoutes.contains(staticRoute)) {
installedRules.add(flowEntry);
devicesStaticRoutes.remove(staticRoute);
}
}
});
});
if (!devicesStaticRoutes.isEmpty()) {
log.info("Found static routes on device {} not installed by ONOS: {}", devId, devicesStaticRoutes);
// FIXME: enable configuration to purge already installed flows.
// It cannot be allowed by default because it may remove needed management routes
// log.warn("Removing from device {} the FlowEntries not expected {}", deviceId, devicesStaticRoutes);
// devicesStaticRoutes.forEach(staticRoute -> editRoute(session, REMOVE, staticRoute));
}
return installedRules;
}
Aggregations