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