import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetMplsTtl;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwTtl;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetQueue;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsList;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsListBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.actions.list.ActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.ActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionBase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
* @param actionsLength length of buckets
* @return ActionsList
*/
- public static List<ActionsList> createActionsList(ByteBuf input, int actionsLength) {
- ActionsListBuilder actionsListBuilder = new ActionsListBuilder();
- List<ActionsList> actionsList = new ArrayList<>();
+ public static List<Action> createActions(ByteBuf input, int actionsLength) {
+ List<Action> actions = new ArrayList<>();
int length = 0;
while (length < actionsLength) {
- int currentActionLength = 0;
- switch(input.readUnsignedShort()) {
- case 0: currentActionLength = input.readUnsignedShort(); //outputActionLength
- actionsList.add(createOutputAction(input, actionsListBuilder));
- break;
- case 11:
- currentActionLength = input.readUnsignedShort();//empty header length
- actionsList.add(createCopyTtlOutAction(input, actionsListBuilder));
+ int type = input.readUnsignedShort();
+ int currentActionLength = input.readUnsignedShort();
+ ActionBuilder actionBuilder = new ActionBuilder();
+ switch(type) {
+ case 0:
+ actions.add(createOutputAction(input, actionBuilder));
break;
-
- case 12:
- currentActionLength = input.readUnsignedShort();//empty header length
- actionsList.add(createCopyTtlInAction(input, actionsListBuilder));
+ case 11:
+ actions.add(createCopyTtlOutAction(input, actionBuilder));
break;
-
- case 15:
- currentActionLength = input.readUnsignedShort();//empty header length
- actionsList.add(createSetMplsTtlAction(input, actionsListBuilder));
+ case 12:
+ actions.add(createCopyTtlInAction(input, actionBuilder));
break;
-
- case 16:
- currentActionLength = input.readUnsignedShort();//empty header length
- actionsList.add(createDecMplsTtlOutAction(input, actionsListBuilder));
+ case 15:
+ actions.add(createSetMplsTtlAction(input, actionBuilder));
break;
-
- case 17:
- currentActionLength = input.readUnsignedShort();
- actionsList.add(createPushVlanAction(input, actionsListBuilder));
+ case 16:
+ actions.add(createDecMplsTtlOutAction(input, actionBuilder));
break;
-
- case 18:
- currentActionLength = input.readUnsignedShort();//empty header length
- actionsList.add(createPopVlanAction(input, actionsListBuilder));
+ case 17:
+ actions.add(createPushVlanAction(input, actionBuilder));
break;
-
- case 19:
- currentActionLength = input.readUnsignedShort();//8
- actionsList.add(createPushMplsAction(input, actionsListBuilder));
+ case 18:
+ actions.add(createPopVlanAction(input, actionBuilder));
break;
-
- case 20:
- currentActionLength = input.readUnsignedShort();//8
- actionsList.add(createPopMplsAction(input, actionsListBuilder));
+ case 19:
+ actions.add(createPushMplsAction(input, actionBuilder));
break;
-
- case 21:
- currentActionLength = input.readUnsignedShort();
- actionsList.add(createSetQueueAction(input, actionsListBuilder));
+ case 20:
+ actions.add(createPopMplsAction(input, actionBuilder));
break;
-
- case 22:
- currentActionLength = input.readUnsignedShort();//8
- actionsList.add(createGroupAction(input, actionsListBuilder));
+ case 21:
+ actions.add(createSetQueueAction(input, actionBuilder));
break;
-
- case 23:
- currentActionLength = input.readUnsignedShort();//8
- actionsList.add(createSetNwTtlAction(input, actionsListBuilder));
+ case 22:
+ actions.add(createGroupAction(input, actionBuilder));
break;
-
- case 24:
- currentActionLength = input.readUnsignedShort();//empty header length
- actionsList.add(createDecNwTtlAction(input, actionsListBuilder));
+ case 23:
+ actions.add(createSetNwTtlAction(input, actionBuilder));
+ break;
+ case 24:
+ actions.add(createDecNwTtlAction(input, actionBuilder));
break;
+ case 25:
+ actions.add(createSetFieldAction(input, actionBuilder, currentActionLength));
+ break;
+ case 26:
+ actions.add(createPushPbbAction(input, actionBuilder));
+ break;
+ case 27:
+ actions.add(createPopPbbAction(input, actionBuilder));
+ break;
+ case 0xFFFF:
+ actions.add(createExperimenterAction(input, actionBuilder));
+ break;
+ default:
+ break;
+ }
+ length += currentActionLength;
+ }
+ return actions;
+ }
+ /**
+ * Creates action ids - actions without values (OpenFlow v1.3)
+ * @param input input ByteBuf
+ * @param actionsLength length of actions
+ * @return ActionsList
+ */
+ public static List<Action> createActionIds(ByteBuf input, int actionsLength) {
+ List<Action> actionsList = new ArrayList<>();
+ int length = 0;
+ ActionBuilder builder;
+ while (length < actionsLength) {
+ builder = new ActionBuilder();
+ int type = input.readUnsignedShort();
+ int currentActionLength = input.readUnsignedShort();
+ switch(type) {
+ case 0:
+ builder.setType(Output.class);
+ break;
+ case 11:
+ builder.setType(CopyTtlOut.class);
+ break;
+ case 12:
+ builder.setType(CopyTtlIn.class);
+ break;
+ case 15:
+ builder.setType(SetMplsTtl.class);
+ break;
+ case 16:
+ builder.setType(DecMplsTtl.class);
+ break;
+ case 17:
+ builder.setType(PushVlan.class);
+ break;
+ case 18:
+ builder.setType(PopVlan.class);
+ break;
+ case 19:
+ builder.setType(PushMpls.class);
+ break;
+ case 20:
+ builder.setType(PopMpls.class);
+ break;
+ case 21:
+ builder.setType(SetQueue.class);
+ break;
+ case 22:
+ builder.setType(Group.class);
+ break;
+ case 23:
+ builder.setType(SetNwTtl.class);
+ break;
+ case 24:
+ builder.setType(DecNwTtl.class);
+ break;
case 25:
- currentActionLength = input.readUnsignedShort();// depends on OXM TLV (match entry)
- actionsList.add(createSetFieldAction(input, actionsListBuilder, currentActionLength));
+ builder.setType(SetField.class);
break;
- case 26:
- currentActionLength = input.readUnsignedShort();//8
- actionsList.add(createPushPbbAction(input, actionsListBuilder));
+ case 26:
+ builder.setType(PushPbb.class);
break;
-
- case 27:
- currentActionLength = input.readUnsignedShort();//empty header length
- actionsList.add(createPopPbbAction(input, actionsListBuilder));
+ case 27:
+ builder.setType(PopPbb.class);
break;
-
- case 0xFFFF:
- currentActionLength = input.readUnsignedShort();
- actionsList.add(createExperimenterAction(input, actionsListBuilder));
+ case 0xFFFF:
+ builder.setType(Experimenter.class);
+ ExperimenterActionBuilder experimenter = new ExperimenterActionBuilder();
+ experimenter.setExperimenter(input.readUnsignedInt());
+ builder.addAugmentation(ExperimenterAction.class, experimenter.build());
break;
default:
break;
}
+ actionsList.add(builder.build());
length += currentActionLength;
}
return actionsList;
}
-
- private static ActionsList createEmptyHeader(Class<? extends org.opendaylight.yang.gen.v1.
- urn.opendaylight.openflow.common.types.rev130731.Action> action,
- ByteBuf in, ActionsListBuilder actionsListBuilder) {
- ActionBuilder actionBuilder = new ActionBuilder();
+
+ private static Action createEmptyHeader(Class<? extends ActionBase> action,
+ ByteBuf in, ActionBuilder actionBuilder) {
actionBuilder.setType(action);
in.skipBytes(PADDING_IN_ACTIONS_HEADER);
- actionsListBuilder.setAction(actionBuilder.build());
- return actionsListBuilder.build();
+ return actionBuilder.build();
}
- private static ActionsList createCopyTtlInAction(ByteBuf in, ActionsListBuilder actionsListBuilder) {
- return createEmptyHeader(CopyTtlIn.class, in, actionsListBuilder);
+ private static Action createCopyTtlInAction(ByteBuf in, ActionBuilder actionBuilder) {
+ return createEmptyHeader(CopyTtlIn.class, in, actionBuilder);
}
- private static ActionsList createCopyTtlOutAction(ByteBuf in, ActionsListBuilder actionsListBuilder) {
- return createEmptyHeader(CopyTtlOut.class, in, actionsListBuilder);
+ private static Action createCopyTtlOutAction(ByteBuf in, ActionBuilder actionBuilder) {
+ return createEmptyHeader(CopyTtlOut.class, in, actionBuilder);
}
- private static ActionsList createDecMplsTtlOutAction(ByteBuf in, ActionsListBuilder actionsListBuilder) {
- return createEmptyHeader(DecMplsTtl.class, in, actionsListBuilder);
+ private static Action createDecMplsTtlOutAction(ByteBuf in, ActionBuilder actionBuilder) {
+ return createEmptyHeader(DecMplsTtl.class, in, actionBuilder);
}
- private static ActionsList createPopVlanAction(ByteBuf in, ActionsListBuilder actionsListBuilder) {
- return createEmptyHeader(PopVlan.class, in, actionsListBuilder);
+ private static Action createPopVlanAction(ByteBuf in, ActionBuilder actionBuilder) {
+ return createEmptyHeader(PopVlan.class, in, actionBuilder);
}
- private static ActionsList createDecNwTtlAction(ByteBuf in, ActionsListBuilder actionsListBuilder) {
- return createEmptyHeader(DecNwTtl.class, in, actionsListBuilder);
+ private static Action createDecNwTtlAction(ByteBuf in, ActionBuilder actionBuilder) {
+ return createEmptyHeader(DecNwTtl.class, in, actionBuilder);
}
- private static ActionsList createPopPbbAction(ByteBuf in, ActionsListBuilder actionsListBuilder) {
- return createEmptyHeader(PopPbb.class, in, actionsListBuilder);
+ private static Action createPopPbbAction(ByteBuf in, ActionBuilder actionBuilder) {
+ return createEmptyHeader(PopPbb.class, in, actionBuilder);
}
- private static ActionsList createOutputAction(ByteBuf in, ActionsListBuilder actionsListBuilder) {
- ActionBuilder actionBuilder = new ActionBuilder();
+ private static Action createOutputAction(ByteBuf in, ActionBuilder actionBuilder) {
actionBuilder.setType(Output.class);
PortActionBuilder port = new PortActionBuilder();
port.setPort(new PortNumber(in.readUnsignedInt()));
MaxLengthActionBuilder maxLen = new MaxLengthActionBuilder();
maxLen.setMaxLength(in.readUnsignedShort());
actionBuilder.addAugmentation(MaxLengthAction.class, maxLen.build());
- actionsListBuilder.setAction(actionBuilder.build());
in.skipBytes(PADDING_IN_OUTPUT_ACTIONS_HEADER);
- return actionsListBuilder.build();
+ return actionBuilder.build();
}
- private static ActionsList createSetMplsTtlAction(ByteBuf in, ActionsListBuilder actionsListBuilder) {
- ActionBuilder actionBuilder = new ActionBuilder();
+ private static Action createSetMplsTtlAction(ByteBuf in, ActionBuilder actionBuilder) {
actionBuilder.setType(SetMplsTtl.class);
MplsTtlActionBuilder mplsTtl = new MplsTtlActionBuilder();
mplsTtl.setMplsTtl(in.readUnsignedByte());
actionBuilder.addAugmentation(MplsTtlAction.class, mplsTtl.build());
- actionsListBuilder.setAction(actionBuilder.build());
in.skipBytes(PADDING_IN_SET_MPLS_TTL_ACTIONS_HEADER);
- return actionsListBuilder.build();
+ return actionBuilder.build();
}
- private static ActionsList createPushAction(Class<? extends org.opendaylight.yang.gen.
- v1.urn.opendaylight.openflow.common.types.rev130731.Action> action,
- ByteBuf in, ActionsListBuilder actionsListBuilder) {
- ActionBuilder actionBuilder = new ActionBuilder();
+ private static Action createPushAction(Class<? extends ActionBase> action,
+ ByteBuf in, ActionBuilder actionBuilder) {
actionBuilder.setType(action);
EthertypeActionBuilder etherType = new EthertypeActionBuilder();
etherType.setEthertype(new EtherType(in.readUnsignedShort()));
actionBuilder.addAugmentation(EthertypeAction.class, etherType.build());
- actionsListBuilder.setAction(actionBuilder.build());
in.skipBytes(PADDING_IN_PUSH_VLAN_ACTIONS_HEADER);
- return actionsListBuilder.build();
+ return actionBuilder.build();
}
- private static ActionsList createPushVlanAction(ByteBuf in, ActionsListBuilder actionsListBuilder) {
- return createPushAction(PushVlan.class, in, actionsListBuilder);
+ private static Action createPushVlanAction(ByteBuf in, ActionBuilder actionBuilder) {
+ return createPushAction(PushVlan.class, in, actionBuilder);
}
- private static ActionsList createPushMplsAction(ByteBuf in, ActionsListBuilder actionsListBuilder) {
- return createPushAction(PushMpls.class, in, actionsListBuilder);
+ private static Action createPushMplsAction(ByteBuf in, ActionBuilder actionBuilder) {
+ return createPushAction(PushMpls.class, in, actionBuilder);
}
- private static ActionsList createPopMplsAction(ByteBuf in, ActionsListBuilder actionsListBuilder) {
- return createPushAction(PopMpls.class, in, actionsListBuilder);
+ private static Action createPopMplsAction(ByteBuf in, ActionBuilder actionBuilder) {
+ return createPushAction(PopMpls.class, in, actionBuilder);
}
- private static ActionsList createPushPbbAction(ByteBuf in, ActionsListBuilder actionsListBuilder) {
- return createPushAction(PushPbb.class, in, actionsListBuilder);
+ private static Action createPushPbbAction(ByteBuf in, ActionBuilder actionBuilder) {
+ return createPushAction(PushPbb.class, in, actionBuilder);
}
- private static ActionsList createSetQueueAction(ByteBuf in, ActionsListBuilder actionsListBuilder) {
- ActionBuilder actionBuilder = new ActionBuilder();
+ private static Action createSetQueueAction(ByteBuf in, ActionBuilder actionBuilder) {
actionBuilder.setType(SetQueue.class);
QueueIdActionBuilder queueId = new QueueIdActionBuilder();
queueId.setQueueId(in.readUnsignedInt());
actionBuilder.addAugmentation(QueueIdAction.class, queueId.build());
- actionsListBuilder.setAction(actionBuilder.build());
- return actionsListBuilder.build();
+ return actionBuilder.build();
}
- private static ActionsList createGroupAction(ByteBuf in, ActionsListBuilder actionsListBuilder) {
- ActionBuilder actionBuilder = new ActionBuilder();
+ private static Action createGroupAction(ByteBuf in, ActionBuilder actionBuilder) {
actionBuilder.setType(Group.class);
GroupIdActionBuilder group = new GroupIdActionBuilder();
group.setGroupId(in.readUnsignedInt());
actionBuilder.addAugmentation(GroupIdAction.class, group.build());
- actionsListBuilder.setAction(actionBuilder.build());
- return actionsListBuilder.build();
+ return actionBuilder.build();
}
- private static ActionsList createExperimenterAction(ByteBuf in, ActionsListBuilder actionsListBuilder) {
- ActionBuilder actionBuilder = new ActionBuilder();
+ private static Action createExperimenterAction(ByteBuf in, ActionBuilder actionBuilder) {
actionBuilder.setType(Experimenter.class);
ExperimenterActionBuilder experimenter = new ExperimenterActionBuilder();
experimenter.setExperimenter(in.readUnsignedInt());
actionBuilder.addAugmentation(ExperimenterAction.class, experimenter.build());
- actionsListBuilder.setAction(actionBuilder.build());
- return actionsListBuilder.build();
+ return actionBuilder.build();
}
- private static ActionsList createSetNwTtlAction(ByteBuf in, ActionsListBuilder actionsListBuilder) {
- ActionBuilder actionBuilder = new ActionBuilder();
+ private static Action createSetNwTtlAction(ByteBuf in, ActionBuilder actionBuilder) {
actionBuilder.setType(SetNwTtl.class);
NwTtlActionBuilder nwTtl = new NwTtlActionBuilder();
nwTtl.setNwTtl(in.readUnsignedByte());
actionBuilder.addAugmentation(NwTtlAction.class, nwTtl.build());
- actionsListBuilder.setAction(actionBuilder.build());
in.skipBytes(PADDING_IN_NW_TTL_ACTIONS_HEADER);
- return actionsListBuilder.build();
+ return actionBuilder.build();
}
- private static ActionsList createSetFieldAction(ByteBuf in, ActionsListBuilder actionsListBuilder, int actionLength) {
- ActionBuilder actionBuilder = new ActionBuilder();
+ private static Action createSetFieldAction(ByteBuf in, ActionBuilder actionBuilder, int actionLength) {
actionBuilder.setType(SetField.class);
OxmFieldsActionBuilder matchEntries = new OxmFieldsActionBuilder();
matchEntries.setMatchEntries(MatchDeserializer.createMatchEntry(in, actionLength - ACTION_HEADER_LENGTH));
actionBuilder.addAugmentation(OxmFieldsAction.class, matchEntries.build());
- actionsListBuilder.setAction(actionBuilder.build());
- return actionsListBuilder.build();
+ return actionBuilder.build();
}
}