Search in sources :

Example 1 with FlowEntityBuilder

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;
}
Also used : FlowEntityBuilder(org.opendaylight.genius.mdsalutil.FlowEntityBuilder) NodeRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef) FlowRef(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowRef) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) AddFlowInput(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput) AddFlowInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)

Example 2 with FlowEntityBuilder

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());
}
Also used : FlowEntityBuilder(org.opendaylight.genius.mdsalutil.FlowEntityBuilder) ArrayList(java.util.ArrayList) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) ActionNxConntrack(org.opendaylight.genius.mdsalutil.actions.ActionNxConntrack) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity) Test(org.junit.Test)

Example 3 with FlowEntityBuilder

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();
}
Also used : MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) FlowEntityBuilder(org.opendaylight.genius.mdsalutil.FlowEntityBuilder) InstructionGotoTable(org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable) MatchEthernetSource(org.opendaylight.genius.mdsalutil.matches.MatchEthernetSource) ArrayList(java.util.ArrayList) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) BigInteger(java.math.BigInteger)

Example 4 with FlowEntityBuilder

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);
}
Also used : FlowEntityBuilder(org.opendaylight.genius.mdsalutil.FlowEntityBuilder) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity)

Aggregations

FlowEntityBuilder (org.opendaylight.genius.mdsalutil.FlowEntityBuilder)4 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)3 ArrayList (java.util.ArrayList)2 BigInteger (java.math.BigInteger)1 Test (org.junit.Test)1 ActionInfo (org.opendaylight.genius.mdsalutil.ActionInfo)1 InstructionInfo (org.opendaylight.genius.mdsalutil.InstructionInfo)1 MatchInfo (org.opendaylight.genius.mdsalutil.MatchInfo)1 ActionNxConntrack (org.opendaylight.genius.mdsalutil.actions.ActionNxConntrack)1 InstructionApplyActions (org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)1 InstructionGotoTable (org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable)1 MatchEthernetSource (org.opendaylight.genius.mdsalutil.matches.MatchEthernetSource)1 MatchMetadata (org.opendaylight.genius.mdsalutil.matches.MatchMetadata)1 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)1 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)1 AddFlowInput (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput)1 AddFlowInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder)1 FlowRef (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowRef)1 NodeRef (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef)1 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)1