2017-12-02 4 views
0

Ich möchte das Äquivalent der folgenden Funktionen ausführen:Wie erstelle ich einen Set-Vlan-Flow?

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 

Wie kann ich das in opendaylight Java-Code? Ich versuchte es anhand einiger Beispiele, die ich finden konnte, aber keine Flüsse erschienen oder manchmal mit genug Feinabstimmung konnte ich einen Teil des Flusses zu sehen bekommen (ich konnte die Ausgabeaktion nie sehen). Ich verwende Carbon (die neueste Version von Carbon) für meine Entwicklung. Lohnt es sich, zum nächtlichen Schnappschuss zu wechseln?

Wenn ich dies mit opendaylight mache, finde ich, dass alle Aktionen, die mit vlan zu tun haben, nicht in meinem Flow erscheinen. Nur der Goto erscheint im Fluss.

=== === UPDATE

ich den folgenden Java-Code verwenden, um den VLAN-Tag (vorgeschlagen von Antwort unten) zu setzen und zu erstellen:

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

Der Code, der eine Fließregel erstellt ist hier:

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

Nach dem Code aufruft ich dies in openvswitch sehen:

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

Und hier ist der Dump aus dem Datenspeicher Config zu diesem Fluss entspricht:

{ 
         "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 
        } 

So ist der Vlan einfach verschwunden Einstellung.

==== End UPDATE ====

==== ==== UPDATE 1

ich den Fluss angemeldet, bevor die Transaktion zu begehen. Hier ist die eingestellte VLAN-Anweisung:

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

Ich kann nichts falsch daran sehen.

=== Ende UPDATE 1 ===

=== 2 Update ===

Wenn ich entfernen Sie das goto und folgen dem Muster des xml hier: https://wiki.opendaylight.org/view/Editing_OpenDaylight_OpenFlow_Plugin:End_to_End_Flows:Example_Flows#Push_VLAN

es funktioniert nur OHNE den goto. Mit anderen Worten, wenn ich den Goto entferne, kann ich den Push-Flow im Config-Datastore sehen. Wenn ich den goto eingebe, erscheint NUR der goto.

==== End Update 2 ====

Ich sehe ein Problem in der issue tracker über vlan fließt in opendaylight soutbound gebrochen, aber es scheint im Jahr 2014 festgelegt worden sind (?).

Ist dies in Stickstoff fixiert und wie kann ich einen Fehler gegen opendaylight einreichen?

Antwort

0

Versuchen Sie folgendes:

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

Dann müssen Sie Ihre Aktionen in Ihren Anweisungen in der folgenden Art und Weise hinzuzufügen:

//ApplyActions 
ApplyActions applyActions = new ApplyActionsBuilder().setAction(actions).build(); 

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

Auch here einen Blick darauf werfen.

+0

Hat leider nicht funktioniert. Meine Tabelle hat immer noch: cookie = 0x523f476a, duration = 0.012s, Tabelle = 2, n_packets = 0, n_bytes = 0, hard_timeout = 30000, Priorität = 35, metadata = 0x523f476a Aktionen = goto_table: 3. – LostInTheFrequencyDomain

+0

Siehe Update oben. Danke für jede Hilfe. – LostInTheFrequencyDomain

+0

Warum setzt setField einen VlanMatchBuilder()? Ich bin verwirrt über das Programmiermodell. – LostInTheFrequencyDomain