use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofpact.actions.ofpact.actions.NxActionNatCaseBuilder in project openflowplugin by opendaylight.
the class ConntrackConvertor method getCtAction.
private List<CtActions> getCtAction(final NxActionConntrack action) {
if (action.getCtActions() == null) {
return null;
}
List<CtActions> ctActions = new ArrayList<>();
for (org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.conntrack.grouping.nx.action.conntrack.CtActions ctAction : action.getCtActions()) {
org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofpact.actions.OfpactActions ofpactAction = ctAction.getOfpactActions();
if (ofpactAction instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofpact.actions.ofpact.actions.NxActionNatCase) {
org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofpact.actions.ofpact.actions.nx.action.nat._case.NxActionNat nxActionNat = ((org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofpact.actions.ofpact.actions.NxActionNatCase) ofpactAction).getNxActionNat();
NxActionNatBuilder nxActionNatBuilder = new 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());
NxActionNatCaseBuilder caseBuilder = new NxActionNatCaseBuilder();
caseBuilder.setNxActionNat(nxActionNatBuilder.build());
CtActionsBuilder ctActionsBuilder = new CtActionsBuilder();
ctActionsBuilder.setOfpactActions(caseBuilder.build());
ctActions.add(ctActionsBuilder.build());
} else if (ofpactAction instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofpact.actions.ofpact.actions.NxActionCtMarkCase) {
org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofpact.actions.ofpact.actions.nx.action.ct.mark._case.NxActionCtMark nxActionCtMark = ((org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofpact.actions.ofpact.actions.NxActionCtMarkCase) ofpactAction).getNxActionCtMark();
NxActionCtMarkBuilder nxActionCtMarkBuilder = new NxActionCtMarkBuilder();
nxActionCtMarkBuilder.setCtMark(nxActionCtMark.getCtMark());
// TODO: ct_mark mask is not supported yet
NxActionCtMarkCaseBuilder caseBuilder = new NxActionCtMarkCaseBuilder();
caseBuilder.setNxActionCtMark(nxActionCtMarkBuilder.build());
CtActionsBuilder ctActionsBuilder = new CtActionsBuilder();
ctActionsBuilder.setOfpactActions(caseBuilder.build());
ctActions.add(ctActionsBuilder.build());
}
}
return ctActions;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofpact.actions.ofpact.actions.NxActionNatCaseBuilder in project openflowplugin by opendaylight.
the class ConntrackCodecTest method createAction.
private Action createAction() {
NxActionConntrackBuilder nxActionConntrackBuilder = new NxActionConntrackBuilder();
nxActionConntrackBuilder.setFlags(1);
nxActionConntrackBuilder.setZoneSrc((long) 2);
nxActionConntrackBuilder.setConntrackZone(3);
nxActionConntrackBuilder.setRecircTable((short) 4);
NxActionNatBuilder nxActionNatBuilder = new NxActionNatBuilder();
nxActionNatBuilder.setFlags(5);
nxActionNatBuilder.setRangePresent(0x3F);
nxActionNatBuilder.setIpAddressMin(new IpAddress("192.168.0.0".toCharArray()));
nxActionNatBuilder.setIpAddressMax(new IpAddress("192.168.10.0".toCharArray()));
nxActionNatBuilder.setPortMin(3000);
nxActionNatBuilder.setPortMax(4000);
NxActionNatCaseBuilder nxActionNatCaseBuilder = new NxActionNatCaseBuilder();
nxActionNatCaseBuilder.setNxActionNat(nxActionNatBuilder.build());
CtActionsBuilder ctActionsBuilder = new CtActionsBuilder();
ctActionsBuilder.setOfpactActions(nxActionNatCaseBuilder.build());
List<CtActions> ctActionsList = new ArrayList<>();
ctActionsList.add(ctActionsBuilder.build());
nxActionNatBuilder = new NxActionNatBuilder();
nxActionNatBuilder.setFlags(5);
nxActionNatBuilder.setRangePresent(0x21);
nxActionNatBuilder.setIpAddressMin(new IpAddress("192.168.0.0".toCharArray()));
nxActionNatBuilder.setPortMax(4000);
nxActionNatCaseBuilder = new NxActionNatCaseBuilder();
nxActionNatCaseBuilder.setNxActionNat(nxActionNatBuilder.build());
ctActionsBuilder = new CtActionsBuilder();
ctActionsBuilder.setOfpactActions(nxActionNatCaseBuilder.build());
ctActionsList.add(ctActionsBuilder.build());
nxActionConntrackBuilder.setCtActions(ctActionsList);
NxActionCtMarkBuilder nxActionCtMarkBuilder = new NxActionCtMarkBuilder();
nxActionCtMarkBuilder.setCtMark((long) 36);
NxActionCtMarkCaseBuilder nxActionCtMarkCaseBuilder = new NxActionCtMarkCaseBuilder();
nxActionCtMarkCaseBuilder.setNxActionCtMark(nxActionCtMarkBuilder.build());
ctActionsBuilder = new CtActionsBuilder();
ctActionsBuilder.setOfpactActions(nxActionCtMarkCaseBuilder.build());
ctActionsList.add(ctActionsBuilder.build());
nxActionConntrackBuilder.setCtActions(ctActionsList);
ExperimenterId experimenterId = new ExperimenterId(NiciraConstants.NX_VENDOR_ID);
ActionBuilder actionBuilder = new ActionBuilder();
actionBuilder.setExperimenterId(experimenterId);
ActionConntrackBuilder actionConntrackBuilder = new ActionConntrackBuilder();
actionConntrackBuilder.setNxActionConntrack(nxActionConntrackBuilder.build());
actionBuilder.setActionChoice(actionConntrackBuilder.build());
return actionBuilder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofpact.actions.ofpact.actions.NxActionNatCaseBuilder in project openflowplugin by opendaylight.
the class ConntrackCodec method deserializeCtAction.
private void deserializeCtAction(final ByteBuf message, final NxActionConntrackBuilder nxActionConntrackBuilder, final int ctActionsLength) {
List<CtActions> ctActionsList = new ArrayList<>();
int processedCtActionsLength = ctActionsLength;
while (processedCtActionsLength > 0) {
int startReaderIndex = message.readerIndex();
if (EncodeConstants.EXPERIMENTER_VALUE == message.readUnsignedShort()) {
// NAT action
// reset indices
message.setIndex(startReaderIndex, message.writerIndex());
final int startIndex = message.readerIndex();
int length = deserializeCtHeader(message);
processedCtActionsLength = processedCtActionsLength - length;
NxActionNatBuilder nxActionNatBuilder = new NxActionNatBuilder();
message.skipBytes(2);
nxActionNatBuilder.setFlags(message.readUnsignedShort());
int rangePresent = message.readUnsignedShort();
nxActionNatBuilder.setRangePresent(rangePresent);
if (0 != (rangePresent & NxActionNatRangePresent.NXNATRANGEIPV4MIN.getIntValue())) {
InetAddress address = InetAddresses.fromInteger((int) message.readUnsignedInt());
nxActionNatBuilder.setIpAddressMin(new IpAddress(address.getHostAddress().toCharArray()));
}
if (0 != (rangePresent & NxActionNatRangePresent.NXNATRANGEIPV4MAX.getIntValue())) {
InetAddress address = InetAddresses.fromInteger((int) message.readUnsignedInt());
nxActionNatBuilder.setIpAddressMax(new IpAddress(address.getHostAddress().toCharArray()));
}
if (0 != (rangePresent & NxActionNatRangePresent.NXNATRANGEPROTOMIN.getIntValue())) {
nxActionNatBuilder.setPortMin(message.readUnsignedShort());
}
if (0 != (rangePresent & NxActionNatRangePresent.NXNATRANGEPROTOMAX.getIntValue())) {
nxActionNatBuilder.setPortMax(message.readUnsignedShort());
}
NxActionNatCaseBuilder caseBuilder = new NxActionNatCaseBuilder();
caseBuilder.setNxActionNat(nxActionNatBuilder.build());
CtActionsBuilder ctActionsBuilder = new CtActionsBuilder();
ctActionsBuilder.setOfpactActions(caseBuilder.build());
ctActionsList.add(ctActionsBuilder.build());
int pad = length - (message.readerIndex() - startIndex);
message.skipBytes(pad);
} else {
// only other possible action here is currently ct_mark
// reset indices
message.setIndex(startReaderIndex, message.writerIndex());
processedCtActionsLength = processedCtActionsLength - SET_FIELD_LENGTH;
deserializeCtHeaderWithoutSubtype(message);
NxActionCtMarkBuilder nxActionCtMarkBuilder = new NxActionCtMarkBuilder();
nxActionCtMarkBuilder.setCtMark(message.readUnsignedInt());
NxActionCtMarkCaseBuilder caseBuilder = new NxActionCtMarkCaseBuilder();
caseBuilder.setNxActionCtMark(nxActionCtMarkBuilder.build());
CtActionsBuilder ctActionsBuilder = new CtActionsBuilder();
ctActionsBuilder.setOfpactActions(caseBuilder.build());
ctActionsList.add(ctActionsBuilder.build());
// padding
message.skipBytes(EncodeConstants.SIZE_OF_INT_IN_BYTES);
}
}
nxActionConntrackBuilder.setCtActions(ctActionsList);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofpact.actions.ofpact.actions.NxActionNatCaseBuilder in project openflowplugin by opendaylight.
the class ConntrackConvertorTest method testConvertToOfJava.
@Test
public void testConvertToOfJava() throws Exception {
final NxActionNatBuilder nxActionNatBuilder = new NxActionNatBuilder().setFlags(1).setRangePresent(2).setIpAddressMin(new IpAddress("192.168.0.0".toCharArray())).setIpAddressMin(new IpAddress("192.168.10.0".toCharArray())).setPortMin(3000).setPortMax(4000);
final CtActionsBuilder ctActionsBuilder = new CtActionsBuilder().setOfpactActions(new NxActionNatCaseBuilder().setNxActionNat(nxActionNatBuilder.build()).build());
List<CtActions> ctAction = new ArrayList<>();
ctAction.add(ctActionsBuilder.build());
final NxConntrackBuilder nxConntrackBuilder = new NxConntrackBuilder().setConntrackZone(1).setFlags(1).setRecircTable((short) 1).setZoneSrc(1L).setCtActions(ctAction);
final NxActionConntrackNodesNodeTableFlowWriteActionsCaseBuilder nxActionConntrackBuilder = new NxActionConntrackNodesNodeTableFlowWriteActionsCaseBuilder().setNxConntrack(nxConntrackBuilder.build());
final NxActionConntrackNodesNodeTableFlowWriteActionsCase actionsCase = nxActionConntrackBuilder.build();
final ActionConntrack actionConntrack = (ActionConntrack) conntrackConvertor.convert(actionsCase).getActionChoice();
Assert.assertEquals(actionsCase.getNxConntrack().getConntrackZone(), actionConntrack.getNxActionConntrack().getConntrackZone());
Assert.assertEquals(actionsCase.getNxConntrack().getFlags(), actionConntrack.getNxActionConntrack().getFlags());
Assert.assertEquals(actionsCase.getNxConntrack().getRecircTable(), actionConntrack.getNxActionConntrack().getRecircTable());
Assert.assertEquals(actionsCase.getNxConntrack().getZoneSrc(), actionConntrack.getNxActionConntrack().getZoneSrc());
NxActionNat natactionCase = ((NxActionNatCase) actionsCase.getNxConntrack().getCtActions().get(0).getOfpactActions()).getNxActionNat();
org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofpact.actions.ofpact.actions.nx.action.nat._case.NxActionNat nataction = ((org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofpact.actions.ofpact.actions.NxActionNatCase) actionConntrack.getNxActionConntrack().getCtActions().get(0).getOfpactActions()).getNxActionNat();
Assert.assertEquals(natactionCase.getFlags(), nataction.getFlags());
Assert.assertEquals(natactionCase.getRangePresent(), nataction.getRangePresent());
Assert.assertEquals(natactionCase.getIpAddressMin().getIpv4Address().getValue(), nataction.getIpAddressMin().getIpv4Address().getValue());
Assert.assertEquals(natactionCase.getIpAddressMin().getIpv4Address().getValue(), nataction.getIpAddressMin().getIpv4Address().getValue());
Assert.assertEquals(natactionCase.getPortMin(), nataction.getPortMin());
Assert.assertEquals(natactionCase.getPortMax(), nataction.getPortMax());
}
Aggregations