如何创建集合VLAN流



我想做以下等同的等同:

sudo ovs-ofctl add-flow s1 table=2,metadata=1379878762,actions=push_vlan:0x8100,mod_vlan_vid:4000,output:6,goto_table:4 -O openflow13

如何在OpenDaylight Java代码中执行此操作?我尝试了一些我可以找到的示例,但是没有出现流量,有时甚至没有进行足够的调整,我可以看到一部分流程(我永远看不到输出操作)。我正在使用碳(最新版本的碳)进行开发。值得切换到夜间快照吗?

当我使用OpenDaylight进行此操作时,我发现与VLAN有关的任何动作都不会出现在我的流程中。只有goto出现在流中。

=== update ===

我使用以下Java代码来设置并创建VLAN标签(以下答案建议):

    private static Instruction createSetVlanAndOutputToPortInstructions( int vlanId,
        String outputPortUri) {
    List<Action> actionList = new ArrayList<>();
    ActionBuilder ab = new ActionBuilder();
    Integer VLAN_ETHERTYPE = 0x8100;
    ActionBuilder actionBuilder = new ActionBuilder();
    //push vlan
    Action pushVlanAction = actionBuilder
        .setOrder(0).setAction(new PushVlanActionCaseBuilder()
            .setPushVlanAction(new PushVlanActionBuilder()
                .setEthernetType(VLAN_ETHERTYPE)
                    .build())
                    .build())
                .build();
    actionList.add(pushVlanAction);
    //set vlan id
    SetVlanIdActionBuilder tab = new SetVlanIdActionBuilder();
    tab.setVlanId(new VlanId((int) vlanId));
    SetVlanIdActionCaseBuilder vidcb = new SetVlanIdActionCaseBuilder();
    vidcb.setSetVlanIdAction(tab.build());
    Action setVlanIdAction = actionBuilder.setOrder(1).setAction(vidcb.build()).build();

    OutputActionBuilder output = new OutputActionBuilder();
    output.setMaxLength(Integer.valueOf(0xffff));
    Uri controllerPort = new Uri(outputPortUri);
    output.setOutputNodeConnector(controllerPort);
    ab = new ActionBuilder();
    ab.setKey(new ActionKey(0));
    ab.setAction(new OutputActionCaseBuilder().setOutputAction(output.build()).build());
    ab.setOrder(2);
    actionList.add(ab.build());
    ApplyActionsBuilder aab = new ApplyActionsBuilder();
    aab.setAction(actionList);
    InstructionBuilder ib = new InstructionBuilder();
    ib.setKey(new InstructionKey(0));
    ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
    return ib.build();
}

创建流量规则的代码在这里:

 FlowBuilder tagPacketFlow = new FlowBuilder().setTableId((short) tableId)
            .setFlowName("metadataMatchSetVlanTagSendToPortAndGoToStripVlanTagTable").setId(flowId)
            .setKey(new FlowKey(flowId)).setCookie(flowCookie);
    MatchBuilder matchBuilder = new MatchBuilder();
    createMetadataMatch(matchBuilder, flowCookie.getValue());
    InstructionBuilder ib = new InstructionBuilder();
    Instruction createVlanTag = FlowUtils.createSetVlanAndOutputToPortInstructions(
            SdnMudConstants.MUD_RULE_HIT_LABEL, outputPortUri);
    InstructionsBuilder insb = new InstructionsBuilder();
    ArrayList<Instruction> instructions = new ArrayList<Instruction>();
    instructions.add(createVlanTag);
    Instruction gotoInstruction = ib.setInstruction(new GoToTableCaseBuilder()
            .setGoToTable(new GoToTableBuilder().setTableId(SdnMudConstants.STRIP_VLAN_RULE_TABLE).build()).build())
            .setOrder(3)
            .setKey(new InstructionKey(0)).build();
    instructions.add(gotoInstruction);
    insb.setInstruction(instructions);
    tagPacketFlow.setMatch(matchBuilder.build()).setInstructions(insb.build())
            .setPriority(35).setBufferId(OFConstants.ANY)
            .setHardTimeout(time).setIdleTimeout(0).setFlags(new FlowModFlags(false, false, false, false, false));

调用代码后,我在OpenVswitch中看到了这一点:

 cookie=0x523f476a, duration=0.012s, table=2, n_packets=0, n_bytes=0, hard_timeout=30000, priority=35,metadata=0x523f476a actions=goto_table:3

这是与此流相对应的配置数据存储的转储:

    {
                        "buffer_id": 4294967295,
                        "cookie": 1379878762,
                        "flags": "",
                        "flow-name": "metadataMatchSetVlanTagSendToPortAndGoToStripVlanTagTable",
                        "hard-timeout": 30000,
                        "id": "toaster.nist.gov/42",
                        "idle-timeout": 0,
                        "instructions": {
                            "instruction": [
                                {
                                    "go-to-table": {
                                        "table_id": 3
                                    },
                                    "order": 0
                                }
                            ]
                        },
                        "match": {
                            "metadata": {
                                "metadata": 1379878762
                            }
                        },
                        "priority": 35,
                        "table_id": 2
                    }

因此,VLAN设置刚刚消失。

==== End Update ======

==== update 1 =====

我在进行交易之前记录了流量。这是集合VLAN指令:

   ApplyActionsCase [_applyActions=ApplyActions 
      [_action=[Action [_action=PushVlanActionCase 
      [_pushVlanAction=PushVlanAction [_ethernetType=33024,
      _vlanId=VlanId [_value=1001], augmentation=[]], augmentation=[]], 
     _key=ActionKey [_order=0], _order=0, augmentation=[]], 
      Action [_action=SetVlanIdActionCase[_setVlanIdAction=SetVlanIdAction
     [_vlanId=VlanId [_value=1001], augmentation=[]], 
     augmentation=[]], _key=ActionKey [_order=1], _order=1, 
     augmentation=[]], Action [_action=OutputActionCase 
     [_outputAction=OutputAction [_maxLength=65535,
     _outputNodeConnector=Uri [_value=openflow:1:6], 
      augmentation=[]], augmentation=[]], 
     _key=ActionKey [_order=2], _order=2,
      augmentation=[]]], augmentation=[]], augmentation=[]]

我看不到任何错误。

=== End Update 1 ===

===更新2 ===

当我删除goto并在此处遵循XML的模式时:https://wiki.opendaylight.org/view/editing_opendaylight_openflow_plugin:end_to_end_end_end_flows:example_flows_flows_flows#push_vlan

它只能在没有goto的情况下工作。换句话说,如果我删除了goto,我可以在配置数据存储中看到推动流。如果我把goto放进去,只出现了。

==== End Update 2 =====

我在问题跟踪器中看到了有关opendaylight soutbound中VLAN流的问题,但它似乎已在2014年被固定(?)。

这是否固定在氮中,我该如何针对Opendaylight提起错误?

尝试以下:

Integer VLAN_ETHERTYPE = 0x8100;
ActionBuilder actionBuilder = new ActionBuilder();
List<Action> actions = new ArrayList<>();
//push vlan
Action pushVlanAction = actionBuilder
    .setOrder(0).setAction(new PushVlanActionCaseBuilder()
        .setPushVlanAction(new PushVlanActionBuilder()
            .setEthernetType(VLAN_ETHERTYPE)
                .build())
                .build())
            .build();
actions.add(pushVlanAction);
//set vlan id
Action setVlanIdAction = actionBuilder
    .setOrder(1).setAction(new SetFieldCaseBuilder()
        .setSetField(new SetFieldBuilder()
            .setVlanMatch(new VlanMatchBuilder()
                .setVlanId(new VlanIdBuilder()
                    .setVlanId(new VlanId(vlanID))
                     .setVlanIdPresent(true)
                .build())
            .build())
        .build())
    .build())
    .build();
actions.add(setVlanIdAction);

然后,您需要以以下方式将操作添加到说明中:

//ApplyActions
ApplyActions applyActions = new ApplyActionsBuilder().setAction(actions).build();
//Instruction
Instruction applyActionsInstruction = new InstructionBuilder() 
        .setOrder(0).setInstruction(new ApplyActionsCaseBuilder()
                .setApplyActions(applyActions) 
                .build()) 
            .build();

也在这里看看。

升级到氮后,我发现我的问题消失了。因此,碳释放似乎有一个错误。不确定何时修复。

最新更新