use of org.opendaylight.genius.mdsalutil.FlowEntityBuilder in project netvirt by opendaylight.
the class NaptEventHandler method buildAndInstallNatFlowsOptionalRpc.
private Future<RpcResult<AddFlowOutput>> buildAndInstallNatFlowsOptionalRpc(BigInteger dpnId, short tableId, long vpnId, long routerId, long bgpVpnId, SessionAddress actualSourceAddress, SessionAddress translatedSourceAddress, NAPTEntryEvent.Protocol protocol, String extGwMacAddress, boolean sendRpc) {
LOG.debug("buildAndInstallNatFlowsOptionalRpc : Build and install table={} flow on dpnId {} and routerId {}", tableId, dpnId, routerId);
// Build the flow for replacing the actual IP and port with the translated IP and port.
int idleTimeout = 0;
if (tableId == NwConstants.OUTBOUND_NAPT_TABLE) {
idleTimeout = NatConstants.DEFAULT_NAPT_IDLE_TIMEOUT;
}
long intranetVpnId;
if (bgpVpnId != NatConstants.INVALID_ID) {
intranetVpnId = bgpVpnId;
} else {
intranetVpnId = routerId;
}
LOG.debug("buildAndInstallNatFlowsOptionalRpc : Intranet VPN ID {} Router ID {}", intranetVpnId, routerId);
String translatedIp = translatedSourceAddress.getIpAddress();
int translatedPort = translatedSourceAddress.getPortNumber();
String actualIp = actualSourceAddress.getIpAddress();
int actualPort = actualSourceAddress.getPortNumber();
String switchFlowRef = NatUtil.getNaptFlowRef(dpnId, tableId, String.valueOf(routerId), actualIp, actualPort);
FlowEntity snatFlowEntity = new FlowEntityBuilder().setDpnId(dpnId).setTableId(tableId).setFlowId(switchFlowRef).setPriority(NatConstants.DEFAULT_NAPT_FLOW_PRIORITY).setFlowName(NatConstants.NAPT_FLOW_NAME).setIdleTimeOut(idleTimeout).setHardTimeOut(0).setCookie(NatUtil.getCookieNaptFlow(routerId)).setMatchInfoList(buildAndGetMatchInfo(actualIp, actualPort, tableId, protocol, intranetVpnId)).setInstructionInfoList(buildAndGetSetActionInstructionInfo(translatedIp, translatedPort, intranetVpnId, vpnId, tableId, protocol, extGwMacAddress)).setSendFlowRemFlag(true).build();
// Install flows using RPC to prevent race with future packet-out that depends on this flow
Future<RpcResult<AddFlowOutput>> addFlowResult = null;
if (sendRpc) {
Flow flow = snatFlowEntity.getFlowBuilder().build();
NodeRef nodeRef = getNodeRef(dpnId);
FlowRef flowRef = getFlowRef(dpnId, flow);
AddFlowInput addFlowInput = new AddFlowInputBuilder(flow).setFlowRef(flowRef).setNode(nodeRef).build();
long startTime = System.currentTimeMillis();
addFlowResult = salFlowServiceRpc.addFlow(addFlowInput);
LOG.debug("buildAndInstallNatFlowsOptionalRpc : Time elapsed for salFlowServiceRpc table {}: {}ms ", tableId, System.currentTimeMillis() - startTime);
// Keep flow installation through MDSAL as well to be able to handle switch failures
startTime = System.currentTimeMillis();
mdsalManager.installFlow(snatFlowEntity);
LOG.trace("buildAndInstallNatFlowsOptionalRpc : Time Elapsed while installing table-{} " + "flow on DPN:{} for snat packet({},{}): {}ms", tableId, dpnId, actualSourceAddress.getIpAddress(), actualSourceAddress.getPortNumber(), System.currentTimeMillis() - startTime);
} else {
long startTime = System.currentTimeMillis();
mdsalManager.syncInstallFlow(snatFlowEntity);
LOG.trace("buildAndInstallNatFlowsOptionalRpc : Time Elapsed while installing table-{} " + "flow on DPN:{} for snat packet({},{}): {}ms", tableId, dpnId, actualSourceAddress.getIpAddress(), actualSourceAddress.getPortNumber(), System.currentTimeMillis() - startTime);
}
LOG.trace("buildAndInstallNatFlowsOptionalRpc : Exited");
return addFlowResult;
}
use of org.opendaylight.genius.mdsalutil.FlowEntityBuilder in project genius by opendaylight.
the class ActionInfoImmutableTest method actionInfoActionKeyDoesNotMagicallyChangeOnFlowEntityGetFlowBuilder.
@Test
public void actionInfoActionKeyDoesNotMagicallyChangeOnFlowEntityGetFlowBuilder() {
FlowEntityBuilder flowEntityBuilder = new FlowEntityBuilder().setDpnId(BigInteger.valueOf(123L)).setTableId((short) 1).setPriority(2).setFlowName("TEST-NAME").setFlowId("TEST-ID").setCookie(BigInteger.valueOf(110100480L));
ActionInfo actionInfo = new ActionNxConntrack(27, 1, 0, 0, (short) 255);
List<ActionInfo> actionInfos = new ArrayList<>();
actionInfos.add(actionInfo);
flowEntityBuilder.addInstructionInfoList(new InstructionApplyActions(actionInfos));
FlowEntity flowEntity = flowEntityBuilder.build();
assertEquals(27, ((InstructionApplyActions) flowEntity.getInstructionInfoList().get(0)).getActionInfos().get(0).getActionKey());
flowEntity.getFlowBuilder();
assertEquals(27, ((InstructionApplyActions) flowEntity.getInstructionInfoList().get(0)).getActionInfos().get(0).getActionKey());
flowEntity.getFlowBuilder();
assertEquals(27, ((InstructionApplyActions) flowEntity.getInstructionInfoList().get(0)).getActionInfos().get(0).getActionKey());
}
use of org.opendaylight.genius.mdsalutil.FlowEntityBuilder in project netvirt by opendaylight.
the class ElanUtils method buildKnownSmacFlow.
public FlowEntity buildKnownSmacFlow(ElanInstance elanInfo, InterfaceInfo interfaceInfo, long macTimeout, String macAddress) {
int lportTag = interfaceInfo.getInterfaceTag();
// Matching metadata and eth_src fields
List<MatchInfo> mkMatches = new ArrayList<>();
mkMatches.add(new MatchMetadata(ElanHelper.getElanMetadataLabel(elanInfo.getElanTag(), lportTag), ElanHelper.getElanMetadataMask()));
mkMatches.add(new MatchEthernetSource(new MacAddress(macAddress)));
List<InstructionInfo> mkInstructions = new ArrayList<>();
mkInstructions.add(new InstructionGotoTable(NwConstants.ELAN_DMAC_TABLE));
BigInteger dpId = interfaceInfo.getDpId();
long elanTag = getElanTag(elanInfo, interfaceInfo);
return new FlowEntityBuilder().setDpnId(dpId).setTableId(NwConstants.ELAN_SMAC_TABLE).setFlowId(getKnownDynamicmacFlowRef(NwConstants.ELAN_SMAC_TABLE, dpId, lportTag, macAddress, elanTag)).setPriority(20).setFlowName(elanInfo.getDescription()).setIdleTimeOut((int) macTimeout).setHardTimeOut(0).setCookie(ElanConstants.COOKIE_ELAN_KNOWN_SMAC.add(BigInteger.valueOf(elanTag))).setMatchInfoList(mkMatches).setInstructionInfoList(mkInstructions).setStrictFlag(true).setSendFlowRemFlag(macTimeout != 0).build();
}
use of org.opendaylight.genius.mdsalutil.FlowEntityBuilder in project netvirt by opendaylight.
the class ElanInterfaceManager method unsetExternalTunnelTable.
/**
* Removes, from External Tunnel table, the flow that translates from VNI to
* elanTag. Important: ensure this method is only called whenever there is
* no other ElanInterface in the specified DPN
*
* @param dpnId
* DPN whose Ext Tunnel table is going to be modified
* @param elanInfo
* holds the elanTag needed for selecting the flow to be removed
*/
public void unsetExternalTunnelTable(BigInteger dpnId, ElanInstance elanInfo) {
// TODO: Use DataStoreJobCoordinator in order to avoid that removing the
// last ElanInstance plus
// adding a new one does (almost at the same time) are executed in that
// exact order
String flowId = getFlowRef(NwConstants.EXTERNAL_TUNNEL_TABLE, elanInfo.getElanTag());
FlowEntity flowEntity = new FlowEntityBuilder().setDpnId(dpnId).setTableId(NwConstants.EXTERNAL_TUNNEL_TABLE).setFlowId(flowId).build();
mdsalManager.removeFlow(flowEntity);
}
Aggregations