2017-12-02 46 views
0

我想做以下等效:如何創建一個設置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設置只是不見了。

====結束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=[]] 

我看不出有什麼問題。

===結束時更新1 ===

===更新=== 2

當我刪除轉到這裏遵循的XML模式: https://wiki.opendaylight.org/view/Editing_OpenDaylight_OpenFlow_Plugin:End_to_End_Flows:Example_Flows#Push_VLAN

它只能在沒有goto的情況下運行。換句話說,如果我刪除goto,我可以在配置數據存儲中看到推送流。如果我把goto放進去,只會出現goto。

====結束時更新2 ====

我看到有關opendaylight soutbound VLAN流量的問題跟蹤一個問題被破壞,但它似乎已被固定在2014年(?)。

這是固定在氮氣中,我怎麼能提交一個bug反對opendaylight?

回答

0

試試這個:

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(); 

而且看一看here

+0

不幸的是沒有工作。我的表仍然有:cookie = 0x523f476a,持續時間= 0.012s,表= 2,n_packets = 0,n_bytes = 0,hard_timeout = 30000,優先級= 35,元數據= 0x523f476a actions = goto_table:3。 – LostInTheFrequencyDomain

+0

請參閱上面的更新。謝謝你的幫助。 – LostInTheFrequencyDomain

+0

爲什麼setField需要一個VlanMatchBuilder()?我對編程模型感到困惑。 – LostInTheFrequencyDomain

相關問題