Search in sources :

Example 1 with ActionConntrack

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionConntrack in project openflowplugin by opendaylight.

the class ConntrackCodec method serializeCtAction.

private void serializeCtAction(final ByteBuf outBuffer, final ActionConntrack action) {
    List<CtActions> ctActionsList = action.getNxActionConntrack().getCtActions();
    if (ctActionsList != null) {
        for (CtActions ctActions : ctActionsList) {
            if (ctActions.getOfpactActions() instanceof NxActionNatCase) {
                NxActionNatCase nxActionNatCase = (NxActionNatCase) ctActions.getOfpactActions();
                NxActionNat natAction = nxActionNatCase.getNxActionNat();
                int natLength = getNatActionLength(natAction);
                int pad = 8 - natLength % 8;
                serializeHeader(natLength + pad, NXAST_NAT_SUBTYPE, outBuffer);
                outBuffer.writeZero(2);
                outBuffer.writeShort(natAction.getFlags().shortValue());
                short rangePresent = natAction.getRangePresent().shortValue();
                outBuffer.writeShort(rangePresent);
                if (0 != (rangePresent & NxActionNatRangePresent.NXNATRANGEIPV4MIN.getIntValue())) {
                    if (null != natAction.getIpAddressMin()) {
                        outBuffer.writeBytes(IetfInetUtil.INSTANCE.ipv4AddressBytes(natAction.getIpAddressMin().getIpv4Address()));
                    }
                }
                if (0 != (rangePresent & NxActionNatRangePresent.NXNATRANGEIPV4MAX.getIntValue())) {
                    if (null != natAction.getIpAddressMax()) {
                        outBuffer.writeBytes(IetfInetUtil.INSTANCE.ipv4AddressBytes(natAction.getIpAddressMax().getIpv4Address()));
                    }
                }
                if (0 != (rangePresent & NxActionNatRangePresent.NXNATRANGEPROTOMIN.getIntValue())) {
                    outBuffer.writeShort(natAction.getPortMin());
                }
                if (0 != (rangePresent & NxActionNatRangePresent.NXNATRANGEPROTOMAX.getIntValue())) {
                    outBuffer.writeShort(natAction.getPortMax());
                }
                outBuffer.writeZero(pad);
            } else if (ctActions.getOfpactActions() instanceof NxActionCtMarkCase) {
                NxActionCtMarkCase nxActionCtMarkCase = (NxActionCtMarkCase) ctActions.getOfpactActions();
                NxActionCtMark ctMarkAction = nxActionCtMarkCase.getNxActionCtMark();
                // structure:
                // 00 19 - set field code
                // 00 10 - set field length
                // 00 01 d6 04
                // xx xx xx xx FIELD VALUE (4 bytes)
                // xx xx xx xx PADDING (4 bytes)
                outBuffer.writeShort(SET_FIELD_CODE);
                outBuffer.writeShort(SET_FIELD_LENGTH);
                outBuffer.writeZero(1);
                outBuffer.writeByte(NXM_FIELD_CODE);
                outBuffer.writeByte(NXM_CT_MARK_FIELD_CODE << 1);
                outBuffer.writeByte(INT_LENGTH);
                outBuffer.writeInt(ctMarkAction.getCtMark().intValue());
                outBuffer.writeZero(INT_LENGTH);
            // TODO: ct_mark mask is not supported yet
            }
        }
    }
}
Also used : NxActionCtMark(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofpact.actions.ofpact.actions.nx.action.ct.mark._case.NxActionCtMark) NxActionCtMarkCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofpact.actions.ofpact.actions.NxActionCtMarkCase) NxActionNatCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofpact.actions.ofpact.actions.NxActionNatCase) CtActions(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.conntrack.grouping.nx.action.conntrack.CtActions) NxActionNat(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofpact.actions.ofpact.actions.nx.action.nat._case.NxActionNat)

Example 2 with ActionConntrack

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionConntrack in project openflowplugin by opendaylight.

the class ConntrackCodec method getActionLength.

private int getActionLength(final ActionConntrack action) {
    int length = 0;
    List<CtActions> ctActionsList = action.getNxActionConntrack().getCtActions();
    if (ctActionsList == null) {
        return length;
    }
    for (CtActions ctActions : ctActionsList) {
        if (ctActions.getOfpactActions() instanceof NxActionNatCase) {
            NxActionNatCase nxActionNatCase = (NxActionNatCase) ctActions.getOfpactActions();
            NxActionNat natAction = nxActionNatCase.getNxActionNat();
            int natLength = getNatActionLength(natAction);
            int pad = 8 - natLength % 8;
            length += natLength + pad;
        } else if (ctActions.getOfpactActions() instanceof NxActionCtMarkCase) {
            length += SET_FIELD_LENGTH;
        }
    }
    LOG.trace("ActionLength :conntrack: length {}", length);
    return length;
}
Also used : NxActionCtMarkCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofpact.actions.ofpact.actions.NxActionCtMarkCase) NxActionNatCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofpact.actions.ofpact.actions.NxActionNatCase) CtActions(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.conntrack.grouping.nx.action.conntrack.CtActions) NxActionNat(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofpact.actions.ofpact.actions.nx.action.nat._case.NxActionNat)

Example 3 with ActionConntrack

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionConntrack in project openflowplugin by opendaylight.

the class ConntrackCodecTest method deserializeTest.

@Test
public void deserializeTest() {
    createBuffer(buffer);
    action = conntrackCodec.deserialize(buffer);
    ActionConntrack result = (ActionConntrack) action.getActionChoice();
    Assert.assertEquals(1, result.getNxActionConntrack().getFlags().shortValue());
    Assert.assertEquals(2, result.getNxActionConntrack().getZoneSrc().intValue());
    Assert.assertEquals(3, result.getNxActionConntrack().getConntrackZone().shortValue());
    Assert.assertEquals(4, result.getNxActionConntrack().getRecircTable().byteValue());
    List<CtActions> ctActions = result.getNxActionConntrack().getCtActions();
    NxActionNatCase nxActionNatCase = (NxActionNatCase) ctActions.get(0).getOfpactActions();
    NxActionNat natAction = nxActionNatCase.getNxActionNat();
    Assert.assertEquals(5, natAction.getFlags().shortValue());
    Assert.assertEquals(0x3F, natAction.getRangePresent().intValue());
    Assert.assertEquals("192.168.0.0", natAction.getIpAddressMin().getIpv4Address().getValue());
    Assert.assertEquals("192.168.10.0", natAction.getIpAddressMax().getIpv4Address().getValue());
    Assert.assertEquals(3000, natAction.getPortMin().shortValue());
    Assert.assertEquals(4000, natAction.getPortMax().shortValue());
    nxActionNatCase = (NxActionNatCase) ctActions.get(1).getOfpactActions();
    natAction = nxActionNatCase.getNxActionNat();
    Assert.assertEquals(5, natAction.getFlags().shortValue());
    Assert.assertEquals(0x21, natAction.getRangePresent().intValue());
    Assert.assertEquals("192.168.0.0", natAction.getIpAddressMin().getIpv4Address().getValue());
    Assert.assertEquals(4000, natAction.getPortMax().shortValue());
    NxActionCtMarkCase nxActionCtMarkCase = (NxActionCtMarkCase) ctActions.get(2).getOfpactActions();
    NxActionCtMark ctMarkAction = nxActionCtMarkCase.getNxActionCtMark();
    Assert.assertEquals(36, ctMarkAction.getCtMark().longValue());
}
Also used : NxActionCtMark(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofpact.actions.ofpact.actions.nx.action.ct.mark._case.NxActionCtMark) NxActionCtMarkCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofpact.actions.ofpact.actions.NxActionCtMarkCase) NxActionNatCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofpact.actions.ofpact.actions.NxActionNatCase) CtActions(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.conntrack.grouping.nx.action.conntrack.CtActions) ActionConntrack(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionConntrack) NxActionNat(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofpact.actions.ofpact.actions.nx.action.nat._case.NxActionNat) Test(org.junit.Test)

Example 4 with ActionConntrack

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionConntrack in project openflowplugin by opendaylight.

the class ConntrackCodecTest method deserializeTestWithoutCtAction.

@Test
public void deserializeTestWithoutCtAction() {
    createBufferWIthoutCtAction(buffer);
    action = conntrackCodec.deserialize(buffer);
    ActionConntrack result = (ActionConntrack) action.getActionChoice();
    Assert.assertEquals(1, result.getNxActionConntrack().getFlags().shortValue());
    Assert.assertEquals(2, result.getNxActionConntrack().getZoneSrc().intValue());
    Assert.assertEquals(3, result.getNxActionConntrack().getConntrackZone().shortValue());
    Assert.assertEquals(4, result.getNxActionConntrack().getRecircTable().byteValue());
}
Also used : ActionConntrack(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionConntrack) Test(org.junit.Test)

Example 5 with ActionConntrack

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionConntrack in project openflowplugin by opendaylight.

the class ConntrackCodec method serialize.

@Override
public void serialize(final Action input, final ByteBuf outBuffer) {
    LOG.trace("serialize :conntrack");
    ActionConntrack action = (ActionConntrack) input.getActionChoice();
    int length = getActionLength(action);
    int pad = length % 8;
    serializeHeader(length + pad + CT_LENGTH, NXAST_CONNTRACK_SUBTYPE, outBuffer);
    outBuffer.writeShort(action.getNxActionConntrack().getFlags().shortValue());
    outBuffer.writeInt(action.getNxActionConntrack().getZoneSrc().intValue());
    outBuffer.writeShort(action.getNxActionConntrack().getConntrackZone().shortValue());
    outBuffer.writeByte(action.getNxActionConntrack().getRecircTable().byteValue());
    outBuffer.writeZero(5);
    serializeCtAction(outBuffer, action);
}
Also used : ActionConntrack(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionConntrack)

Aggregations

ActionConntrack (org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionConntrack)5 Test (org.junit.Test)3 CtActions (org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.conntrack.grouping.nx.action.conntrack.CtActions)3 NxActionCtMarkCase (org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofpact.actions.ofpact.actions.NxActionCtMarkCase)3 NxActionNatCase (org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofpact.actions.ofpact.actions.NxActionNatCase)3 NxActionNat (org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofpact.actions.ofpact.actions.nx.action.nat._case.NxActionNat)3 NxActionCtMark (org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofpact.actions.ofpact.actions.nx.action.ct.mark._case.NxActionCtMark)2 NxConntrackBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.conntrack.grouping.NxConntrackBuilder)2 ArrayList (java.util.ArrayList)1 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)1 NxActionConntrack (org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.conntrack.grouping.NxActionConntrack)1 NxActionConntrackNodesNodeTableFlowWriteActionsCase (org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nodes.node.table.flow.instructions.instruction.instruction.write.actions._case.write.actions.action.action.NxActionConntrackNodesNodeTableFlowWriteActionsCase)1 NxActionConntrackNodesNodeTableFlowWriteActionsCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nodes.node.table.flow.instructions.instruction.instruction.write.actions._case.write.actions.action.action.NxActionConntrackNodesNodeTableFlowWriteActionsCaseBuilder)1 CtActions (org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.conntrack.grouping.nx.conntrack.CtActions)1 CtActionsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.conntrack.grouping.nx.conntrack.CtActionsBuilder)1 NxActionNatCase (org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.ofpact.actions.ofpact.actions.NxActionNatCase)1 NxActionNatCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.ofpact.actions.ofpact.actions.NxActionNatCaseBuilder)1 NxActionNat (org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.ofpact.actions.ofpact.actions.nx.action.nat._case.NxActionNat)1 NxActionNatBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.ofpact.actions.ofpact.actions.nx.action.nat._case.NxActionNatBuilder)1