Search in sources :

Example 21 with ExtensionTreatment

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

the class OplinkPowerConfigUtil method getChannelAttenuation.

/**
 * Gets specified channel attenuation.
 *
 * @param portNum the port number
 * @param och channel signal
 * @return atteuation in 0.01 dB
 */
private Long getChannelAttenuation(PortNumber portNum, OchSignal och) {
    FlowEntry flowEntry = findFlow(portNum, och);
    if (flowEntry == null) {
        return null;
    }
    List<Instruction> instructions = flowEntry.treatment().allInstructions();
    for (Instruction ins : instructions) {
        if (ins.type() != Instruction.Type.EXTENSION) {
            continue;
        }
        ExtensionTreatment ext = ((Instructions.ExtensionInstructionWrapper) ins).extensionInstruction();
        if (ext.type() == ExtensionTreatmentType.ExtensionTreatmentTypes.OPLINK_ATTENUATION.type()) {
            return (long) ((OplinkAttenuation) ext).getAttenuation();
        }
    }
    return null;
}
Also used : Instruction(org.onosproject.net.flow.instructions.Instruction) FlowEntry(org.onosproject.net.flow.FlowEntry) ExtensionTreatment(org.onosproject.net.flow.instructions.ExtensionTreatment)

Example 22 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)

Example 23 with ExtensionTreatment

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

the class KubevirtRoutingSnatHandler method setStatefulSnatUpstreamRules.

private void setStatefulSnatUpstreamRules(KubevirtNode gatewayNode, KubevirtRouter router, Ip4Address routerSnatIp, MacAddress peerRouterMacAddress, boolean install) {
    MacAddress routerMacAddress = getRouterMacAddress(router);
    if (routerMacAddress == null) {
        return;
    }
    if (routerSnatIp == null || peerRouterMacAddress == null) {
        return;
    }
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchEthDst(routerMacAddress);
    TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
    ExtensionTreatment natTreatment = RulePopulatorUtil.niciraConnTrackTreatmentBuilder(driverService, gatewayNode.intgBridge()).commit(true).natFlag(CT_NAT_SRC_FLAG).natAction(true).natIp(routerSnatIp).natPortMin(TpPort.tpPort(TP_PORT_MINIMUM_NUM)).natPortMax(TpPort.tpPort(TP_PORT_MAXIMUM_NUM)).build();
    tBuilder.extension(natTreatment, gatewayNode.intgBridge()).setEthDst(peerRouterMacAddress).setEthSrc(DEFAULT_GATEWAY_MAC).setOutput(externalPatchPortNum(deviceService, gatewayNode));
    flowService.setRule(appId, gatewayNode.intgBridge(), selector.build(), tBuilder.build(), PRIORITY_STATEFUL_SNAT_RULE, GW_ENTRY_TABLE, install);
}
Also used : TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) KubevirtNetworkingUtil.getRouterMacAddress(org.onosproject.kubevirtnetworking.util.KubevirtNetworkingUtil.getRouterMacAddress) MacAddress(org.onlab.packet.MacAddress) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ExtensionTreatment(org.onosproject.net.flow.instructions.ExtensionTreatment)

Example 24 with ExtensionTreatment

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

the class KubevirtRoutingSnatHandler method setStatefulSnatDownstreamRuleForRouter.

private void setStatefulSnatDownstreamRuleForRouter(KubevirtNode gatewayNode, KubevirtRouter router, IpAddress routerSnatIp, KubevirtNetwork externalNetwork, boolean install) {
    MacAddress routerMacAddress = getRouterMacAddress(router);
    if (routerMacAddress == null) {
        log.warn("Failed to set stateful snat downstream rule because " + "there's no br-int port for device {}", gatewayNode.intgBridge());
        return;
    }
    if (externalNetwork == null) {
        log.warn("Failed to set stateful snat downstream rule because " + "there's no external network router {}", router.name());
        return;
    }
    TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
    TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
    sBuilder.matchEthType(Ethernet.TYPE_IPV4);
    if (externalNetwork.type() == VLAN) {
        sBuilder.matchVlanId(VlanId.vlanId(externalNetwork.segmentId()));
        tBuilder.popVlan();
    }
    sBuilder.matchIPDst(IpPrefix.valueOf(routerSnatIp, 32));
    ExtensionTreatment natTreatment = RulePopulatorUtil.niciraConnTrackTreatmentBuilder(driverService, gatewayNode.intgBridge()).commit(false).natAction(true).table((short) GW_DROP_TABLE).build();
    tBuilder.setEthSrc(routerMacAddress).extension(natTreatment, gatewayNode.intgBridge());
    flowService.setRule(appId, gatewayNode.intgBridge(), sBuilder.build(), tBuilder.build(), PRIORITY_STATEFUL_SNAT_RULE, GW_ENTRY_TABLE, install);
}
Also used : TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) KubevirtNetworkingUtil.getRouterMacAddress(org.onosproject.kubevirtnetworking.util.KubevirtNetworkingUtil.getRouterMacAddress) MacAddress(org.onlab.packet.MacAddress) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ExtensionTreatment(org.onosproject.net.flow.instructions.ExtensionTreatment)

Example 25 with ExtensionTreatment

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

the class OpenstackRoutingSnatHandler method setStatefulSnatDownstreamRule.

private void setStatefulSnatDownstreamRule(DeviceId deviceId, IpPrefix gatewayIp, boolean install) {
    Set<TrafficSelector> selectors = Sets.newConcurrentHashSet();
    ImmutableSet<Byte> ipv4Proto = ImmutableSet.of(IPv4.PROTOCOL_TCP, IPv4.PROTOCOL_UDP);
    ipv4Proto.forEach(proto -> {
        TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
        sBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(gatewayIp).matchIPProtocol(proto);
        selectors.add(sBuilder.build());
    });
    ExtensionTreatment natTreatment = RulePopulatorUtil.niciraConnTrackTreatmentBuilder(driverService, deviceId).commit(false).natAction(true).table((short) 0).build();
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().extension(natTreatment, deviceId).build();
    selectors.forEach(s -> {
        osFlowRuleService.setRule(appId, deviceId, s, treatment, 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)

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