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;
}
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;
}
}
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);
}
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);
}
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);
});
}
Aggregations