Search in sources :

Example 11 with ExtensionTreatment

use of org.onosproject.net.flow.instructions.ExtensionTreatment in project onos by opennetworkinglab.

the class RulePopulatorUtil method buildExtension.

/**
 * Returns tunnel destination extension treatment object.
 *
 * @param deviceService driver service
 * @param deviceId device id to apply this treatment
 * @param remoteIp tunnel destination ip address
 * @return extension treatment
 */
public static ExtensionTreatment buildExtension(DeviceService deviceService, DeviceId deviceId, Ip4Address remoteIp) {
    Device device = deviceService.getDevice(deviceId);
    if (!checkTreatmentResolver(device)) {
        return null;
    }
    if (device == null) {
        return null;
    }
    ExtensionTreatmentResolver resolver = device.as(ExtensionTreatmentResolver.class);
    ExtensionTreatment treatment = resolver.getExtensionInstruction(NICIRA_SET_TUNNEL_DST.type());
    try {
        treatment.setPropertyValue(TUNNEL_DST, remoteIp);
        return treatment;
    } catch (ExtensionPropertyException e) {
        log.warn("Failed to get tunnelDst extension treatment for {} " + "because of {}", deviceId, e);
        return null;
    }
}
Also used : Device(org.onosproject.net.Device) ExtensionTreatmentResolver(org.onosproject.net.behaviour.ExtensionTreatmentResolver) ExtensionTreatment(org.onosproject.net.flow.instructions.ExtensionTreatment) ExtensionPropertyException(org.onosproject.net.flow.instructions.ExtensionPropertyException)

Example 12 with ExtensionTreatment

use of org.onosproject.net.flow.instructions.ExtensionTreatment in project onos by opennetworkinglab.

the class OpenstackRoutingSnatHandler method setStatefulSnatUpstreamRule.

private void setStatefulSnatUpstreamRule(OpenstackNode gwNode, IpAddress gatewayIp, long vni, ExternalPeerRouter extPeerRouter, int minPortNum, int maxPortNum, boolean install) {
    TrafficSelector selector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchEthDst(DEFAULT_GATEWAY_MAC).matchTunnelId(vni).build();
    TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
    // we do not consider to much like port range on removing the rules...
    if (install) {
        ExtensionTreatment natTreatment = RulePopulatorUtil.niciraConnTrackTreatmentBuilder(driverService, gwNode.intgBridge()).commit(true).natFlag(CT_NAT_SRC_FLAG).natAction(true).natIp(gatewayIp).natPortMin(TpPort.tpPort(minPortNum)).natPortMax(TpPort.tpPort(maxPortNum)).build();
        tBuilder.extension(natTreatment, gwNode.intgBridge()).setEthDst(extPeerRouter.macAddress()).setEthSrc(DEFAULT_GATEWAY_MAC).setOutput(gwNode.uplinkPortNum());
    }
    osFlowRuleService.setRule(appId, gwNode.intgBridge(), selector, tBuilder.build(), PRIORITY_STATEFUL_SNAT_RULE, GW_COMMON_TABLE, install);
}
Also used : TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ExtensionTreatment(org.onosproject.net.flow.instructions.ExtensionTreatment)

Example 13 with ExtensionTreatment

use of org.onosproject.net.flow.instructions.ExtensionTreatment in project onos by opennetworkinglab.

the class OpenstackSecurityGroupHandler method populateSecurityGroupRule.

private void populateSecurityGroupRule(SecurityGroupRule sgRule, InstancePort instPort, IpPrefix remoteIp, boolean install) {
    if (!checkProtocol(sgRule.getProtocol())) {
        return;
    }
    Set<TrafficSelector> selectors = buildSelectors(sgRule, Ip4Address.valueOf(instPort.ipAddress().toInetAddress()), remoteIp, instPort.networkId());
    if (selectors == null || selectors.isEmpty()) {
        return;
    }
    // if the device is not available we do not perform any action
    if (instPort.deviceId() == null || !deviceService.isAvailable(instPort.deviceId())) {
        return;
    }
    // in case a port is bound to multiple security groups, we do NOT remove
    // egress rules unless all security groups bound to the port to be removed
    Port osPort = osNetService.port(instPort.portId());
    if (!install && osPort != null && sgRule.getDirection().equalsIgnoreCase(EGRESS)) {
        List<String> sgIds = osPort.getSecurityGroups();
        if (!sgIds.contains(sgRule.getSecurityGroupId()) && !sgIds.isEmpty()) {
            return;
        }
    }
    // XXX All egress traffic needs to go through connection tracking module,
    // which might hurt its performance.
    ExtensionTreatment ctTreatment = niciraConnTrackTreatmentBuilder(driverService, instPort.deviceId()).commit(true).build();
    TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
    int aclTable;
    if (sgRule.getDirection().equalsIgnoreCase(EGRESS)) {
        aclTable = ACL_EGRESS_TABLE;
        tBuilder.transition(ACL_RECIRC_TABLE);
    } else {
        aclTable = ACL_INGRESS_TABLE;
        tBuilder.extension(ctTreatment, instPort.deviceId()).transition(JUMP_TABLE);
    }
    int finalAclTable = aclTable;
    selectors.forEach(selector -> {
        osFlowRuleService.setRule(appId, instPort.deviceId(), selector, tBuilder.build(), PRIORITY_ACL_RULE, finalAclTable, install);
    });
}
Also used : InstancePort(org.onosproject.openstacknetworking.api.InstancePort) Port(org.openstack4j.model.network.Port) TpPort(org.onlab.packet.TpPort) NeutronPort(org.openstack4j.openstack.networking.domain.NeutronPort) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ExtensionTreatment(org.onosproject.net.flow.instructions.ExtensionTreatment)

Example 14 with ExtensionTreatment

use of org.onosproject.net.flow.instructions.ExtensionTreatment in project onos by opennetworkinglab.

the class RulePopulatorUtil method buildExtension.

/**
 * Returns tunnel destination extension treatment object.
 *
 * @param deviceService driver service
 * @param deviceId device id to apply this treatment
 * @param remoteIp tunnel destination ip address
 * @return extension treatment
 */
public static ExtensionTreatment buildExtension(DeviceService deviceService, DeviceId deviceId, Ip4Address remoteIp) {
    Device device = deviceService.getDevice(deviceId);
    if (!checkTreatmentResolver(device)) {
        return null;
    }
    if (device == null) {
        return null;
    }
    ExtensionTreatmentResolver resolver = device.as(ExtensionTreatmentResolver.class);
    ExtensionTreatment treatment = resolver.getExtensionInstruction(NICIRA_SET_TUNNEL_DST.type());
    try {
        treatment.setPropertyValue(TUNNEL_DST, remoteIp);
        return treatment;
    } catch (ExtensionPropertyException e) {
        log.warn("Failed to get tunnelDst extension treatment for {} " + "because of {}", deviceId, e);
        return null;
    }
}
Also used : Device(org.onosproject.net.Device) ExtensionTreatmentResolver(org.onosproject.net.behaviour.ExtensionTreatmentResolver) ExtensionTreatment(org.onosproject.net.flow.instructions.ExtensionTreatment) ExtensionPropertyException(org.onosproject.net.flow.instructions.ExtensionPropertyException)

Example 15 with ExtensionTreatment

use of org.onosproject.net.flow.instructions.ExtensionTreatment in project onos by opennetworkinglab.

the class RulePopulatorUtil method buildLoadExtension.

/**
 * Returns the nicira load extension treatment.
 *
 * @param device        device instance
 * @param field         field code
 * @param value         value to load
 * @return load extension treatment
 */
public static ExtensionTreatment buildLoadExtension(Device device, long field, long value) {
    if (!checkTreatmentResolver(device)) {
        return null;
    }
    ExtensionTreatmentResolver resolver = device.as(ExtensionTreatmentResolver.class);
    ExtensionTreatment treatment = resolver.getExtensionInstruction(NICIRA_LOAD.type());
    int ofsNbits = OFF_SET_BIT << 6 | (REMAINDER_BIT - 1);
    try {
        treatment.setPropertyValue(OFF_SET_N_BITS, ofsNbits);
        treatment.setPropertyValue(DESTINATION, field);
        treatment.setPropertyValue(VALUE, value);
        return treatment;
    } catch (ExtensionPropertyException e) {
        log.error("Failed to set nicira load extension treatment for {}", device.id());
        return null;
    }
}
Also used : ExtensionTreatmentResolver(org.onosproject.net.behaviour.ExtensionTreatmentResolver) ExtensionTreatment(org.onosproject.net.flow.instructions.ExtensionTreatment) ExtensionPropertyException(org.onosproject.net.flow.instructions.ExtensionPropertyException)

Aggregations

ExtensionTreatment (org.onosproject.net.flow.instructions.ExtensionTreatment)35 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)17 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)17 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)16 TrafficSelector (org.onosproject.net.flow.TrafficSelector)16 ExtensionTreatmentResolver (org.onosproject.net.behaviour.ExtensionTreatmentResolver)12 ExtensionPropertyException (org.onosproject.net.flow.instructions.ExtensionPropertyException)11 DeviceId (org.onosproject.net.DeviceId)8 Device (org.onosproject.net.Device)7 MacAddress (org.onlab.packet.MacAddress)3 DriverHandler (org.onosproject.net.driver.DriverHandler)3 Pod (io.fabric8.kubernetes.api.model.Pod)2 IpAddress (org.onlab.packet.IpAddress)2 TpPort (org.onlab.packet.TpPort)2 KubevirtNetworkingUtil.getRouterMacAddress (org.onosproject.kubevirtnetworking.util.KubevirtNetworkingUtil.getRouterMacAddress)2 ExtensionTreatmentType (org.onosproject.net.flow.instructions.ExtensionTreatmentType)2 OFAction (org.projectfloodlight.openflow.protocol.action.OFAction)2 OFActionNiciraCt (org.projectfloodlight.openflow.protocol.action.OFActionNiciraCt)2 OFActionNiciraLoad (org.projectfloodlight.openflow.protocol.action.OFActionNiciraLoad)2 OFActionNiciraMove (org.projectfloodlight.openflow.protocol.action.OFActionNiciraMove)2