use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.ofpact.actions.ofpact.actions.NxActionNatCase 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
}
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.ofpact.actions.ofpact.actions.NxActionNatCase 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;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.ofpact.actions.ofpact.actions.NxActionNatCase 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());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.ofpact.actions.ofpact.actions.NxActionNatCase in project openflowplugin by opendaylight.
the class ConntrackConvertor method getCtAction.
private List<org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.conntrack.grouping.nx.action.conntrack.CtActions> getCtAction(final NxConntrack action) {
if (action.getCtActions() == null) {
return null;
}
List<org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.conntrack.grouping.nx.action.conntrack.CtActions> ctActions = new ArrayList<>();
for (CtActions ctAction : action.getCtActions()) {
OfpactActions ofpactAction = ctAction.getOfpactActions();
if (ofpactAction instanceof NxActionNatCase) {
NxActionNat nxActionNat = ((NxActionNatCase) ofpactAction).getNxActionNat();
org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofpact.actions.ofpact.actions.nx.action.nat._case.NxActionNatBuilder nxActionNatBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofpact.actions.ofpact.actions.nx.action.nat._case.NxActionNatBuilder();
nxActionNatBuilder.setFlags(nxActionNat.getFlags());
nxActionNatBuilder.setRangePresent(nxActionNat.getRangePresent());
nxActionNatBuilder.setIpAddressMin(nxActionNat.getIpAddressMin());
nxActionNatBuilder.setIpAddressMax(nxActionNat.getIpAddressMax());
nxActionNatBuilder.setPortMin(nxActionNat.getPortMin());
nxActionNatBuilder.setPortMax(nxActionNat.getPortMax());
org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofpact.actions.ofpact.actions.NxActionNatCaseBuilder caseBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofpact.actions.ofpact.actions.NxActionNatCaseBuilder();
caseBuilder.setNxActionNat(nxActionNatBuilder.build());
org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.conntrack.grouping.nx.action.conntrack.CtActionsBuilder ctActionsBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.conntrack.grouping.nx.action.conntrack.CtActionsBuilder();
ctActionsBuilder.setOfpactActions(caseBuilder.build());
ctActions.add(ctActionsBuilder.build());
} else if (ofpactAction instanceof NxActionCtMarkCase) {
NxActionCtMark nxActionCtMark = ((NxActionCtMarkCase) ofpactAction).getNxActionCtMark();
org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofpact.actions.ofpact.actions.nx.action.ct.mark._case.NxActionCtMarkBuilder nxActionCtMarkBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofpact.actions.ofpact.actions.nx.action.ct.mark._case.NxActionCtMarkBuilder();
nxActionCtMarkBuilder.setCtMark(nxActionCtMark.getCtMark());
// TODO: ct_mark mask is not supported yet
org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofpact.actions.ofpact.actions.NxActionCtMarkCaseBuilder caseBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofpact.actions.ofpact.actions.NxActionCtMarkCaseBuilder();
caseBuilder.setNxActionCtMark(nxActionCtMarkBuilder.build());
org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.conntrack.grouping.nx.action.conntrack.CtActionsBuilder ctActionsBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.conntrack.grouping.nx.action.conntrack.CtActionsBuilder();
ctActionsBuilder.setOfpactActions(caseBuilder.build());
ctActions.add(ctActionsBuilder.build());
}
}
return ctActions;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.ofpact.actions.ofpact.actions.NxActionNatCase in project openflowplugin by opendaylight.
the class ConntrackConvertorTest method testConvertFromOfJava.
@Test
public void testConvertFromOfJava() throws Exception {
org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofpact.actions.ofpact.actions.nx.action.nat._case.NxActionNatBuilder nxActionNatBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofpact.actions.ofpact.actions.nx.action.nat._case.NxActionNatBuilder().setFlags(1).setRangePresent(2).setIpAddressMin(new IpAddress("192.168.0.0".toCharArray())).setIpAddressMax(new IpAddress("192.168.10.0".toCharArray())).setPortMin(3000).setPortMax(4000);
org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.conntrack.grouping.nx.action.conntrack.CtActionsBuilder ctActionsBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.conntrack.grouping.nx.action.conntrack.CtActionsBuilder().setOfpactActions(new org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofpact.actions.ofpact.actions.NxActionNatCaseBuilder().setNxActionNat(nxActionNatBuilder.build()).build());
List<org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.conntrack.grouping.nx.action.conntrack.CtActions> ctActions = new ArrayList<>();
ctActions.add(ctActionsBuilder.build());
final NxActionConntrackBuilder nxActionConntrackBuilder = new NxActionConntrackBuilder().setConntrackZone(1).setFlags(1).setRecircTable((short) 1).setZoneSrc(1L).setCtActions(ctActions);
final ActionConntrackBuilder actionConntrackBuilder = new ActionConntrackBuilder().setNxActionConntrack(nxActionConntrackBuilder.build());
final ActionBuilder actionBuilder = new ActionBuilder().setActionChoice(actionConntrackBuilder.build());
final Action groupingAction = actionBuilder.build();
final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action = conntrackConvertor.convert(groupingAction, ActionPath.INVENTORY_FLOWNODE_TABLE_WRITE_ACTIONS);
final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action1 = conntrackConvertor.convert(groupingAction, ActionPath.FLOWS_STATISTICS_UPDATE_WRITE_ACTIONS);
final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action2 = conntrackConvertor.convert(groupingAction, ActionPath.FLOWS_STATISTICS_UPDATE_APPLY_ACTIONS);
final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action3 = conntrackConvertor.convert(groupingAction, ActionPath.GROUP_DESC_STATS_UPDATED_BUCKET_ACTION);
final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action4 = conntrackConvertor.convert(groupingAction, ActionPath.FLOWS_STATISTICS_RPC_WRITE_ACTIONS);
final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action5 = conntrackConvertor.convert(groupingAction, ActionPath.FLOWS_STATISTICS_RPC_APPLY_ACTIONS);
Assert.assertEquals(1, ((NxActionConntrackNodesNodeTableFlowWriteActionsCase) action).getNxConntrack().getConntrackZone().longValue());
Assert.assertEquals(1L, ((NxActionConntrackNodesNodeTableFlowWriteActionsCase) action).getNxConntrack().getZoneSrc().longValue());
Assert.assertEquals(1, ((NxActionConntrackNodesNodeTableFlowWriteActionsCase) action).getNxConntrack().getRecircTable().intValue());
Assert.assertEquals(1, ((NxActionConntrackNodesNodeTableFlowWriteActionsCase) action).getNxConntrack().getFlags().intValue());
NxActionNat natActionCase = ((NxActionNatCase) ((NxActionConntrackNodesNodeTableFlowWriteActionsCase) action).getNxConntrack().getCtActions().get(0).getOfpactActions()).getNxActionNat();
Assert.assertEquals(1, natActionCase.getFlags().shortValue());
Assert.assertEquals(2, natActionCase.getRangePresent().intValue());
Assert.assertEquals("192.168.0.0", natActionCase.getIpAddressMin().getIpv4Address().getValue());
Assert.assertEquals("192.168.10.0", natActionCase.getIpAddressMax().getIpv4Address().getValue());
Assert.assertEquals(3000, natActionCase.getPortMin().shortValue());
Assert.assertEquals(4000, natActionCase.getPortMax().shortValue());
Assert.assertEquals(1, ((NxActionConntrackNotifFlowsStatisticsUpdateWriteActionsCase) action1).getNxConntrack().getConntrackZone().longValue());
Assert.assertEquals(1L, ((NxActionConntrackNotifFlowsStatisticsUpdateWriteActionsCase) action1).getNxConntrack().getZoneSrc().longValue());
Assert.assertEquals(1, ((NxActionConntrackNotifFlowsStatisticsUpdateWriteActionsCase) action1).getNxConntrack().getRecircTable().intValue());
Assert.assertEquals(1, ((NxActionConntrackNotifFlowsStatisticsUpdateWriteActionsCase) action1).getNxConntrack().getFlags().intValue());
NxActionNat natActionCase1 = ((NxActionNatCase) ((NxActionConntrackNodesNodeTableFlowWriteActionsCase) action).getNxConntrack().getCtActions().get(0).getOfpactActions()).getNxActionNat();
Assert.assertEquals(1, natActionCase1.getFlags().shortValue());
Assert.assertEquals(2, natActionCase1.getRangePresent().intValue());
Assert.assertEquals("192.168.0.0", natActionCase1.getIpAddressMin().getIpv4Address().getValue());
Assert.assertEquals("192.168.10.0", natActionCase1.getIpAddressMax().getIpv4Address().getValue());
Assert.assertEquals(3000, natActionCase1.getPortMin().shortValue());
Assert.assertEquals(4000, natActionCase1.getPortMax().shortValue());
Assert.assertEquals(1, ((NxActionConntrackNotifFlowsStatisticsUpdateApplyActionsCase) action2).getNxConntrack().getConntrackZone().longValue());
Assert.assertEquals(1L, ((NxActionConntrackNotifFlowsStatisticsUpdateApplyActionsCase) action2).getNxConntrack().getZoneSrc().longValue());
Assert.assertEquals(1, ((NxActionConntrackNotifFlowsStatisticsUpdateApplyActionsCase) action2).getNxConntrack().getRecircTable().intValue());
Assert.assertEquals(1, ((NxActionConntrackNotifFlowsStatisticsUpdateApplyActionsCase) action2).getNxConntrack().getFlags().intValue());
NxActionNat natActionCase2 = ((NxActionNatCase) ((NxActionConntrackNodesNodeTableFlowWriteActionsCase) action).getNxConntrack().getCtActions().get(0).getOfpactActions()).getNxActionNat();
Assert.assertEquals(1, natActionCase2.getFlags().shortValue());
Assert.assertEquals(2, natActionCase2.getRangePresent().intValue());
Assert.assertEquals("192.168.0.0", natActionCase2.getIpAddressMin().getIpv4Address().getValue());
Assert.assertEquals("192.168.10.0", natActionCase2.getIpAddressMax().getIpv4Address().getValue());
Assert.assertEquals(3000, natActionCase2.getPortMin().shortValue());
Assert.assertEquals(4000, natActionCase2.getPortMax().shortValue());
NxActionNat natActionCase3 = ((NxActionNatCase) ((NxActionConntrackNodesNodeTableFlowWriteActionsCase) action).getNxConntrack().getCtActions().get(0).getOfpactActions()).getNxActionNat();
Assert.assertEquals(1, natActionCase3.getFlags().shortValue());
Assert.assertEquals(2, natActionCase3.getRangePresent().intValue());
Assert.assertEquals("192.168.0.0", natActionCase3.getIpAddressMin().getIpv4Address().getValue());
Assert.assertEquals("192.168.10.0", natActionCase3.getIpAddressMax().getIpv4Address().getValue());
Assert.assertEquals(3000, natActionCase3.getPortMin().shortValue());
Assert.assertEquals(4000, natActionCase3.getPortMax().shortValue());
Assert.assertEquals(1, ((NxActionConntrackNotifGroupDescStatsUpdatedCase) action3).getNxConntrack().getConntrackZone().longValue());
Assert.assertEquals(1L, ((NxActionConntrackNotifGroupDescStatsUpdatedCase) action3).getNxConntrack().getZoneSrc().longValue());
Assert.assertEquals(1, ((NxActionConntrackNotifGroupDescStatsUpdatedCase) action3).getNxConntrack().getRecircTable().intValue());
Assert.assertEquals(1, ((NxActionConntrackNotifGroupDescStatsUpdatedCase) action3).getNxConntrack().getFlags().intValue());
Assert.assertEquals(1, ((NxActionConntrackNotifDirectStatisticsUpdateWriteActionsCase) action4).getNxConntrack().getConntrackZone().longValue());
Assert.assertEquals(1L, ((NxActionConntrackNotifDirectStatisticsUpdateWriteActionsCase) action4).getNxConntrack().getZoneSrc().longValue());
Assert.assertEquals(1, ((NxActionConntrackNotifDirectStatisticsUpdateWriteActionsCase) action4).getNxConntrack().getRecircTable().intValue());
Assert.assertEquals(1, ((NxActionConntrackNotifDirectStatisticsUpdateWriteActionsCase) action4).getNxConntrack().getFlags().intValue());
Assert.assertEquals(1, ((NxActionConntrackNotifDirectStatisticsUpdateApplyActionsCase) action5).getNxConntrack().getConntrackZone().longValue());
Assert.assertEquals(1L, ((NxActionConntrackNotifDirectStatisticsUpdateApplyActionsCase) action5).getNxConntrack().getZoneSrc().longValue());
Assert.assertEquals(1, ((NxActionConntrackNotifDirectStatisticsUpdateApplyActionsCase) action5).getNxConntrack().getRecircTable().intValue());
Assert.assertEquals(1, ((NxActionConntrackNotifDirectStatisticsUpdateApplyActionsCase) action5).getNxConntrack().getFlags().intValue());
}
Aggregations