table_id = 0
 flow_entry.set_flow_table_id(table_id)
 flow_id = 21
 flow_entry.set_flow_id(flow_id)
 flow_entry.set_flow_priority(flow_priority = 1012)
 flow_entry.set_flow_cookie(cookie = 401)
 flow_entry.set_flow_cookie_mask(cookie_mask = 255)
 flow_entry.set_flow_hard_timeout(hard_timeout = 1200)
 flow_entry.set_flow_idle_timeout(idle_timeout = 3400)
 
 # --- Instruction: 'Apply-action'
 #     Actions:     'PushVlan'
 #                  'SetField'
 #                  'Output'
 instruction = Instruction(instruction_order = 0)
 action = PushVlanHeaderAction(action_order = 0)
 action.set_eth_type(eth_type = push_eth_type)
 instruction.add_apply_action(action)    
 action = SetFieldAction(action_order = 1)
 action.set_vlan_id(vid = push_vlan_id)
 instruction.add_apply_action(action)    
 action = OutputAction(action_order = 2, port = output_port)
 instruction.add_apply_action(action)
 flow_entry.add_instruction(instruction)
 
 # --- Match Fields: Ethernet Type
 #                   Ethernet Source Address
 #                   Ethernet Destination Address
 #                   Input Port
 match = Match()    
 match.set_eth_type(eth_type)
Esempio n. 2
0
def of_demo_15():
    f = "cfg.yml"
    d = {}
    if (load_dict_from_file(f, d) is False):
        print("Config file '%s' read error: " % f)
        exit()

    try:
        ctrlIpAddr = d['ctrlIpAddr']
        ctrlPortNum = d['ctrlPortNum']
        ctrlUname = d['ctrlUname']
        ctrlPswd = d['ctrlPswd']
        nodeName = d['nodeName']
        rundelay = d['rundelay']
    except:
        print("Failed to get Controller device attributes")
        exit(0)

    print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
    print("<<< Demo 15 Start")
    print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")

    ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd)
    ofswitch = OFSwitch(ctrl, nodeName)

    # --- Flow Match: Ethernet Type
    #                 VLAN ID
    #                 Input Port
    eth_type = ETH_TYPE_IPv4
    vlan_id = 100
    input_port = 3

    # --- Flow Actions: Push VLAN: Ethernet Type
    #                   Set Field: VLAN ID
    #                   Output:    Port Number
    push_eth_type = ETH_TYPE_DOT1AD  # 802.1ad VLAN tagged frame
    push_vlan_id = 200
    output_port = 5

    print("<<< 'Controller': %s, 'OpenFlow' switch: '%s'" %
          (ctrlIpAddr, nodeName))

    print "\n"
    print("<<< Set OpenFlow flow on the Controller")
    print(
        "        Match:  Ethernet Type (%s)\n"
        "                VLAN ID (%s)\n"
        "                Input Port (%s)" %
        (hex(eth_type), vlan_id, input_port))
    print("        Action: Push VLAN (Ethernet Type=%s)" %
          (hex(push_eth_type)))
    print("                Set Field (VLAN ID=%s)" % (push_vlan_id))
    print("                Output (to Physical Port Number %s)" %
          (output_port))

    time.sleep(rundelay)

    flow_entry = FlowEntry()
    flow_entry.set_flow_name(flow_name="Push VLAN")
    table_id = 0
    flow_entry.set_flow_table_id(table_id)
    flow_id = 22
    flow_entry.set_flow_id(flow_id)
    flow_entry.set_flow_priority(flow_priority=1013)
    flow_entry.set_flow_cookie(cookie=407)
    flow_entry.set_flow_cookie_mask(cookie_mask=255)
    flow_entry.set_flow_hard_timeout(hard_timeout=3400)
    flow_entry.set_flow_idle_timeout(idle_timeout=3400)

    # --- Instruction: 'Apply-actions'
    #     Actions:     'PushVlan'
    #                  'SetField'
    #                  'Output'
    instruction = Instruction(instruction_order=0)
    action = PushVlanHeaderAction(order=0)
    action.set_eth_type(eth_type=push_eth_type)
    instruction.add_apply_action(action)
    action = SetFieldAction(order=1)
    action.set_vlan_id(vid=push_vlan_id)
    instruction.add_apply_action(action)
    action = OutputAction(order=2, port=output_port)
    instruction.add_apply_action(action)
    flow_entry.add_instruction(instruction)

    # --- Match Fields: Ethernet Type
    #                   Ethernet Source Address
    #                   Ethernet Destination Address
    #                   Input Port
    match = Match()
    match.set_eth_type(eth_type)
    match.set_vlan_id(vlan_id)
    match.set_in_port(in_port=input_port)
    flow_entry.add_match(match)

    print("\n")
    print("<<< Flow to send:")
    print flow_entry.get_payload()
    time.sleep(rundelay)
    result = ofswitch.add_modify_flow(flow_entry)
    status = result.get_status()
    if (status.eq(STATUS.OK)):
        print("<<< Flow successfully added to the Controller")
    else:
        print("\n")
        print("!!!Demo terminated, reason: %s" % status.brief().lower())
        exit(0)

    print("\n")
    print("<<< Get configured flow from the Controller")
    time.sleep(rundelay)
    result = ofswitch.get_configured_flow(table_id, flow_id)
    status = result.get_status()
    if (status.eq(STATUS.OK)):
        print("<<< Flow successfully read from the Controller")
        print("Flow info:")
        flow = result.get_data()
        print json.dumps(flow, indent=4)
    else:
        print("\n")
        print("!!!Demo terminated, reason: %s" % status.brief().lower())
        exit(0)

    print("\n")
    print(
        "<<< Delete flow with id of '%s' from the Controller's cache "
        "and from the table '%s' on the '%s' node" %
        (flow_id, table_id, nodeName))
    time.sleep(rundelay)
    result = ofswitch.delete_flow(flow_entry.get_flow_table_id(),
                                  flow_entry.get_flow_id())
    status = result.get_status()
    if (status.eq(STATUS.OK)):
        print("<<< Flow successfully removed from the Controller")
    else:
        print("\n")
        print("!!!Demo terminated, reason: %s" % status.brief().lower())
        exit(0)

    print("\n")
    print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
    print(">>> Demo End")
    print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
Esempio n. 3
0
def of_demo_26():
    f = "cfg.yml"
    d = {}
    if (load_dict_from_file(f, d) is False):
        print("Config file '%s' read error: " % f)
        exit()

    try:
        ctrlIpAddr = d['ctrlIpAddr']
        ctrlPortNum = d['ctrlPortNum']
        ctrlUname = d['ctrlUname']
        ctrlPswd = d['ctrlPswd']
        nodeName = d['nodeName']
        rundelay = d['rundelay']
    except:
        print("Failed to get Controller device attributes")
        exit(0)

    print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
    print("<<< Demo 26 Start")
    print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")

    ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd)
    ofswitch = OFSwitch(ctrl, nodeName)

    print("<<< 'Controller': %s, 'OpenFlow' switch: '%s'" %
          (ctrlIpAddr, nodeName))

    flow_table_id = 0
    flow_id_base = 12
    flow_id = flow_id_base
    flowEntries = []

    # Sample flow entry
    flow_entry = FlowEntry()
    flow_entry.set_flow_cookie(6001)
    flow_entry.set_flow_table_id(flow_table_id)
    flow_entry.set_flow_id(flow_id)
    flow_id += 1
    flow_entry.set_flow_idle_timeout(12000)
    flow_entry.set_flow_hard_timeout(12000)
    flow_entry.set_flow_priority(1000)

    instruction = Instruction(instruction_order=0)
    action = DropAction(order=0)
    instruction.add_apply_action(action)
    flow_entry.add_instruction(instruction)

    match = Match()
    match.set_eth_type(ETH_TYPE_ARP)
    match.set_eth_src("00:11:22:33:44:55")
    match.set_eth_dst("aa:bb:cc:dd:ee:ff")
    flow_entry.add_match(match)

    flowEntries.append(flow_entry)

    # Sample flow entry
    flow_entry = FlowEntry()
    flow_entry.set_flow_cookie(7001)
    flow_entry.set_flow_table_id(flow_table_id)
    flow_entry.set_flow_id(flow_id)
    flow_id += 1
    flow_entry.set_flow_idle_timeout(2400)
    flow_entry.set_flow_hard_timeout(2400)
    flow_entry.set_flow_priority(2000)

    instruction = Instruction(instruction_order=0)
    action = OutputAction(order=0, port="CONTROLLER", max_len=60)
    instruction.add_apply_action(action)
    flow_entry.add_instruction(instruction)

    match = Match()
    match.set_eth_type(ETH_TYPE_IPv4)
    match.set_ipv4_src("1.2.3.4/32")
    match.set_ipv4_dst("192.168.1.11/32")
    flow_entry.add_match(match)

    flowEntries.append(flow_entry)

    # Sample flow entry
    flow_entry = FlowEntry()
    flow_entry.set_flow_cookie(800)
    flow_entry.set_flow_table_id(flow_table_id)
    flow_entry.set_flow_id(flow_id)
    flow_id += 1
    flow_entry.set_flow_hard_timeout(1800)
    flow_entry.set_flow_idle_timeout(1800)
    flow_entry.set_flow_priority(3000)

    instruction = Instruction(instruction_order=0)
    action = OutputAction(order=0, port=5)
    instruction.add_apply_action(action)
    action = OutputAction(order=1, port=6)
    instruction.add_apply_action(action)
    action = OutputAction(order=2, port=7)
    instruction.add_apply_action(action)

    flow_entry.add_instruction(instruction)

    match = Match()
    match.set_in_port(1)

    flow_entry.add_match(match)

    flowEntries.append(flow_entry)

    # Sample flow entry
    flow_entry = FlowEntry()
    flow_entry.set_flow_cookie(1234)
    flow_entry.set_flow_table_id(flow_table_id)
    flow_entry.set_flow_id(flow_id)
    flow_id += 1
    flow_entry.set_flow_hard_timeout(0)
    flow_entry.set_flow_idle_timeout(0)
    flow_entry.set_flow_priority(4000)

    instruction = Instruction(instruction_order=0)

    action = PushVlanHeaderAction(order=0)
    action.set_eth_type(ETH_TYPE_QINQ)
    instruction.add_apply_action(action)

    action = SetFieldAction(order=1)
    action.set_vlan_id(100)
    instruction.add_apply_action(action)

    action = PushVlanHeaderAction(order=2)
    action.set_eth_type(ETH_TYPE_DOT1Q)
    instruction.add_apply_action(action)

    action = SetFieldAction(order=3)
    action.set_vlan_id(998)
    instruction.add_apply_action(action)

    action = OutputAction(order=4, port=111)
    instruction.add_apply_action(action)

    flow_entry.add_instruction(instruction)

    match = Match()
    match.set_eth_type(ETH_TYPE_ARP)
    match.set_vlan_id(998)
    match.set_in_port(in_port=110)

    flow_entry.add_match(match)

    flowEntries.append(flow_entry)

    # Sample flow entry
    flow_entry = FlowEntry()
    flow_entry.set_flow_cookie(1234)
    flow_entry.set_flow_table_id(flow_table_id)
    flow_entry.set_flow_id(flow_id)
    flow_id += 1
    flow_entry.set_flow_hard_timeout(0)
    flow_entry.set_flow_idle_timeout(0)
    flow_entry.set_flow_priority(4000)

    instruction = Instruction(instruction_order=0)

    action = PushVlanHeaderAction(order=0)
    action.set_eth_type(ETH_TYPE_QINQ)
    instruction.add_apply_action(action)

    action = SetFieldAction(order=1)
    action.set_vlan_id(100)
    instruction.add_apply_action(action)

    action = PushVlanHeaderAction(order=2)
    action.set_eth_type(ETH_TYPE_DOT1Q)
    instruction.add_apply_action(action)

    action = SetFieldAction(order=3)
    action.set_vlan_id(998)
    instruction.add_apply_action(action)

    action = OutputAction(order=4, port=111)
    instruction.add_apply_action(action)

    flow_entry.add_instruction(instruction)

    match = Match()
    match.set_eth_type(ETH_TYPE_IPv4)
    match.set_vlan_id(998)
    match.set_in_port(in_port=110)

    flow_entry.add_match(match)

    flowEntries.append(flow_entry)

    # Sample flow entry
    flow_entry = FlowEntry()
    flow_entry.set_flow_cookie(1234)
    flow_entry.set_flow_table_id(flow_table_id)
    flow_entry.set_flow_id(flow_id)
    flow_id += 1
    flow_entry.set_flow_hard_timeout(0)
    flow_entry.set_flow_idle_timeout(0)
    flow_entry.set_flow_priority(4000)

    instruction = Instruction(instruction_order=0)

    action = PopVlanHeaderAction(order=0)
    instruction.add_apply_action(action)

    action = OutputAction(order=1, port=110)
    instruction.add_apply_action(action)

    flow_entry.add_instruction(instruction)

    match = Match()
    match.set_eth_type(ETH_TYPE_ARP)
    match.set_vlan_id(100)
    match.set_in_port(111)

    flow_entry.add_match(match)

    flowEntries.append(flow_entry)

    # Sample flow entry
    flow_entry = FlowEntry()
    flow_entry.set_flow_cookie(1234)
    flow_entry.set_flow_table_id(flow_table_id)
    flow_entry.set_flow_id(flow_id)
    flow_id += 1
    flow_entry.set_flow_hard_timeout(0)
    flow_entry.set_flow_idle_timeout(0)
    flow_entry.set_flow_priority(4000)

    instruction = Instruction(instruction_order=0)

    action = PopVlanHeaderAction(order=0)
    instruction.add_apply_action(action)

    action = OutputAction(order=1, port=110)
    instruction.add_apply_action(action)

    flow_entry.add_instruction(instruction)

    match = Match()
    match.set_eth_type(ETH_TYPE_IPv4)
    match.set_vlan_id(100)
    match.set_in_port(111)

    flow_entry.add_match(match)

    flowEntries.append(flow_entry)

    print("\n")
    print("<<< Remove configured flows from the Controller")
    ofswitch.delete_flows(flow_table_id)

    print("\n")
    print("<<< Set OpenFlow flows on the Controller")

    print("\n")
    print("<<< Flows to be configured:")

    flowEntries = sorted(flowEntries, key=lambda fe: fe.get_flow_priority())
    for fe in flowEntries:
        print(" %s" % fe.to_ofp_oxm_syntax())

    time.sleep(rundelay)
    success = True
    for fe in flowEntries:
        result = ofswitch.add_modify_flow(fe)
        status = result.get_status()
        if (status.eq(STATUS.OK)):
            pass
        else:
            success = False
            print("\n")
            print("!!!Demo terminated, failed to add flow:\n '%s'" %
                  fe.to_ofp_oxm_syntax())
            print(" Failure reason: %s" % status.detailed())

    if success:
        print "\n"
        print("<<< Flows successfully added to the Controller")
    else:
        print "\n"
        print("<<< Removing all flows from the Controller")
        ofswitch.delete_flows(flow_table_id)
        exit(0)

    print("\n")
    print("<<< Get configured flows from the Controller")
    time.sleep(rundelay)

    print("\n")
    print("<<< Configured flows:")
    result = ofswitch.get_configured_FlowEntries(flow_table_id=0)
    status = result.get_status()
    if (status.eq(STATUS.OK)):
        data = result.get_data()
        flowEntries = sorted(data, key=lambda fe: fe.get_flow_priority())
        for fe in flowEntries:
            print " %s" % fe.to_ofp_oxm_syntax()
    else:
        print("\n")
        print("!!!Demo terminated, reason: %s" % status.brief().lower())
        exit(0)

    print("\n")
    print("<<< Get configured flows by IDs from the Controller:")
    time.sleep(rundelay)
    for i in range(flow_id_base, flow_id):
        result = ofswitch.get_configured_FlowEntry(flow_table_id, i)
        status = result.get_status()
        if (status.eq(STATUS.OK)):
            print(" -- Flow id '%s'" % i)
            fe = result.get_data()
            print " %s" % fe.to_ofp_oxm_syntax()
        else:
            print("\n")
            print("!!!Demo terminated, reason: %s" % status.brief().lower())
            print("<<< Removing all flows from the Controller")
            ofswitch.delete_flows(flow_table_id)
            exit(0)

    time.sleep(rundelay)

    print("\n")
    print("<<< Remove configured flows from the Controller")
    ofswitch.delete_flows(flow_table_id)

    time.sleep(rundelay)

    print("\n")
    print("<<< Get configured flows from the Controller")
    result = ofswitch.get_configured_FlowEntries(flow_table_id=0)
    status = result.get_status()
    if (status.eq(STATUS.DATA_NOT_FOUND)):
        print("\n")
        print "<<< No configured flows"
    else:
        print("\n")
        print("!!!Demo terminated, reason: %s" % status.detailed())
        exit(0)

    print("\n")
    print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
    print(">>> Demo End")
    print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
Esempio n. 4
0
def of_demo_25():
    f = "cfg.yml"
    d = {}
    if(load_dict_from_file(f, d) is False):
        print("Config file '%s' read error: " % f)
        exit()

    try:
        ctrlIpAddr = d['ctrlIpAddr']
        ctrlPortNum = d['ctrlPortNum']
        ctrlUname = d['ctrlUname']
        ctrlPswd = d['ctrlPswd']
        nodeName = d['nodeName']
        rundelay = d['rundelay']
    except:
        print ("Failed to get Controller device attributes")
        exit(0)

    print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
    print ("<<< Demo 25 Start")
    print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")



    ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd)
    ofswitch = OFSwitch(ctrl, nodeName)

    table_id = 0
    priority = 500
    cookie = 1000
    cookie_mask = 255
    customer_port = 110
    provider_port = 111
    qinq_eth_type = ETH_TYPE_STAG   # 802.1ad (QinQ) VLAN tagged frame
    dot1q_eth_type = ETH_TYPE_CTAG  # 802.1q VLAN tagged frame
    arp_eth_type = ETH_TYPE_ARP
    ip_eth_type = ETH_TYPE_IPv4
    provider_vlan_id = 100          # Provider VLAN
    customer_vlan_id = 998          # Customer VLAN
    first_flow_id = 31

    print ("<<< 'Controller': %s, 'OpenFlow' switch: '%s'"
           % (ctrlIpAddr, nodeName))

    # ---------------------------------------------------
    # First flow entry
    # ---------------------------------------------------
    print "\n"
    print ("<<< Set OpenFlow flow on the Controller")
    print ("        Match:  Ethernet Type (%s)\n"
           "                VLAN ID (%s)\n"
           "                Input Port (%s)"
           % (hex(arp_eth_type), customer_vlan_id, customer_port))
    print ("        Action: Push VLAN (Ethernet Type %s)\n"
           "                Set Field (VLAN ID %s)\n"
           "                Push VLAN (Ethernet Type %s)\n"
           "                Set Field (VLAN ID %s)\n"
           "                Output (Physical Port number %s)"
           % (hex(qinq_eth_type), provider_vlan_id,
              hex(dot1q_eth_type), customer_vlan_id,
              provider_port))

    time.sleep(rundelay)

    flow_id = first_flow_id
    flow_entry1 = FlowEntry()
    flow_entry1.set_flow_table_id(table_id)
    fname = "[MLX1-A] Test flow (match:inport=110,arp;" + \
            "actions:push-QINQ-tag,mod_vlan=100," + \
            "push-DOT1Q-tag,mod_vlan=998,output:111)"
    flow_entry1.set_flow_name(flow_name=fname)
    flow_entry1.set_flow_id(flow_id)
    flow_entry1.set_flow_hard_timeout(hard_timeout=600)
    flow_entry1.set_flow_idle_timeout(idle_timeout=300)
    flow_entry1.set_flow_priority(priority)
    flow_entry1.set_flow_cookie(cookie)
    flow_entry1.set_flow_cookie_mask(cookie_mask)

    instruction = Instruction(instruction_order=0)

    action_order = 0
    action = PushVlanHeaderAction(action_order)
    action.set_eth_type(qinq_eth_type)
    instruction.add_apply_action(action)

    action_order += 1
    action = SetFieldAction(action_order)
    action.set_vlan_id(provider_vlan_id)
    instruction.add_apply_action(action)

    action_order += 1
    action = PushVlanHeaderAction(action_order)
    action.set_eth_type(dot1q_eth_type)
    instruction.add_apply_action(action)

    action_order += 1
    action = SetFieldAction(action_order)
    action.set_vlan_id(customer_vlan_id)
    instruction.add_apply_action(action)

    action_order += 1
    action = OutputAction(action_order, provider_port)
    instruction.add_apply_action(action)

    flow_entry1.add_instruction(instruction)

    match = Match()

    match.set_eth_type(arp_eth_type)
    match.set_vlan_id(customer_vlan_id)
    match.set_in_port(in_port=customer_port)

    flow_entry1.add_match(match)

    print ("\n")
    print ("<<< Flow to send:")
    print flow_entry1.get_payload()
    time.sleep(rundelay)
    result = ofswitch.add_modify_flow(flow_entry1)
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print ("<<< Flow successfully added to the Controller")
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.detailed())
        delete_flows(ofswitch, table_id, range(first_flow_id, flow_id+1))
        exit(0)

    # ---------------------------------------------------
    # Second flow entry
    # ---------------------------------------------------
    print "\n"
    print ("<<< Set OpenFlow flow on the Controller")
    print ("        Match:  Ethernet Type (%s)\n"
           "                VLAN ID (%s)\n"
           "                Input Port (%s)"
           % (hex(ip_eth_type), customer_vlan_id, customer_port))
    print ("        Action: Push VLAN (Ethernet Type %s)\n"
           "                Set Field (VLAN ID %s)\n"
           "                Push VLAN (Ethernet Type %s)\n"
           "                Set Field (VLAN ID %s)\n"
           "                Output (Physical Port number %s)"
           % (hex(qinq_eth_type), provider_vlan_id,
              hex(dot1q_eth_type), customer_vlan_id,
              provider_port))

    time.sleep(rundelay)

    flow_id += 1
    flow_entry2 = FlowEntry()
    flow_entry2.set_flow_table_id(table_id)
    fname = "[MLX1-A] Test flow (match:inport=110,ip;" + \
            "actions:push-QINQ-tag,mod_vlan=100,output:111)"
    flow_entry2.set_flow_name(flow_name=fname)
    flow_entry2.set_flow_id(flow_id)
    flow_entry2.set_flow_hard_timeout(hard_timeout=600)
    flow_entry2.set_flow_idle_timeout(idle_timeout=300)
    flow_entry2.set_flow_priority(priority)
    flow_entry2.set_flow_cookie(cookie)
    flow_entry2.set_flow_cookie_mask(cookie_mask)

    instruction = Instruction(instruction_order=0)

    action_order = 0
    action = PushVlanHeaderAction(action_order)
    action.set_eth_type(qinq_eth_type)
    instruction.add_apply_action(action)

    action_order += 1
    action = SetFieldAction(action_order)
    action.set_vlan_id(provider_vlan_id)
    instruction.add_apply_action(action)

    action_order += 1
    action = PushVlanHeaderAction(action_order)
    action.set_eth_type(dot1q_eth_type)
    instruction.add_apply_action(action)

    action_order += 1
    action = SetFieldAction(action_order)
    action.set_vlan_id(customer_vlan_id)
    instruction.add_apply_action(action)

    action_order += 1
    action = OutputAction(action_order, provider_port)
    instruction.add_apply_action(action)

    flow_entry2.add_instruction(instruction)

    match = Match()

    match.set_eth_type(ip_eth_type)
    match.set_vlan_id(customer_vlan_id)
    match.set_in_port(in_port=customer_port)

    flow_entry2.add_match(match)

    print ("\n")
    print ("<<< Flow to send:")
    print flow_entry2.get_payload()
    time.sleep(rundelay)
    result = ofswitch.add_modify_flow(flow_entry2)
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print ("<<< Flow successfully added to the Controller")
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.detailed())
        delete_flows(ofswitch, table_id, range(first_flow_id, flow_id+1))
        exit(0)

    # ---------------------------------------------------
    # Third flow entry
    # ---------------------------------------------------
    print "\n"
    print ("<<< Set OpenFlow flow on the Controller")
    print ("        Match:  Ethernet Type (%s)\n"
           "                VLAN ID (%s)\n"
           "                Input Port (%s)"
           % (hex(arp_eth_type), provider_vlan_id, provider_port))
    print ("        Action: Pop VLAN\n"
           "                Output (Physical Port number %s)"
           % (customer_port))

    time.sleep(rundelay)

    flow_id += 1
    flow_entry3 = FlowEntry()
    flow_entry3.set_flow_table_id(table_id)
    fname = "[MLX1-A] Test flow (match:inport=111,arp,vid=100;" + \
            "actions:pop-vlan-tag,output=110)"
    flow_entry3.set_flow_name(flow_name=fname)
    flow_entry3.set_flow_id(flow_id)
    flow_entry3.set_flow_hard_timeout(hard_timeout=600)
    flow_entry3.set_flow_idle_timeout(idle_timeout=300)
    flow_entry3.set_flow_priority(priority)
    flow_entry3.set_flow_cookie(cookie)
    flow_entry3.set_flow_cookie_mask(cookie_mask)

    instruction = Instruction(instruction_order=0)

    action_order = 0
    action = PopVlanHeaderAction(action_order)
    instruction.add_apply_action(action)

    action_order += 1
    action = OutputAction(action_order, customer_port)
    instruction.add_apply_action(action)

    flow_entry3.add_instruction(instruction)

    match = Match()
    match.set_eth_type(arp_eth_type)
    match.set_vlan_id(provider_vlan_id)
    match.set_in_port(provider_port)

    flow_entry3.add_match(match)

    print ("\n")
    print ("<<< Flow to send:")
    print flow_entry3.get_payload()
    time.sleep(rundelay)
    result = ofswitch.add_modify_flow(flow_entry3)
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print ("<<< Flow successfully added to the Controller")
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.detailed())
        delete_flows(ofswitch, table_id, range(first_flow_id, flow_id+1))
        exit(0)

    # ---------------------------------------------------
    # Fourth flow entry
    # ---------------------------------------------------
    print "\n"
    print ("<<< Set OpenFlow flow on the Controller")
    print ("        Match:  Ethernet Type (%s)\n"
           "                VLAN ID (%s)\n"
           "                Input Port (%s)"
           % (hex(ip_eth_type), provider_vlan_id, provider_port))
    print ("        Action: Pop VLAN\n"
           "                Output (Physical Port number %s)"
           % (customer_port))

    time.sleep(rundelay)

    flow_id += 1
    flow_entry4 = FlowEntry()
    flow_entry4.set_flow_table_id(table_id)
    flow_entry4.set_flow_id(flow_id)
    fname = "[MLX1-A] Test flow (match:inport=111,ip,vid=100;" + \
            "actions:pop-vlan-tag,output=110)"
    flow_entry4.set_flow_name(flow_name=fname)
    flow_entry4.set_flow_hard_timeout(hard_timeout=600)
    flow_entry4.set_flow_idle_timeout(idle_timeout=300)
    flow_entry4.set_flow_priority(priority)
    flow_entry4.set_flow_cookie(cookie)
    flow_entry4.set_flow_cookie_mask(cookie_mask)

    instruction = Instruction(instruction_order=0)

    action_order = 0
    action = PopVlanHeaderAction(action_order)
    instruction.add_apply_action(action)

    action_order += 1
    action = OutputAction(action_order, customer_port)
    instruction.add_apply_action(action)

    flow_entry4.add_instruction(instruction)

    match = Match()
    match.set_eth_type(ip_eth_type)
    match.set_vlan_id(provider_vlan_id)
    match.set_in_port(provider_port)

    flow_entry4.add_match(match)

    print ("\n")
    print ("<<< Flow to send:")
    print flow_entry4.get_payload()
    time.sleep(rundelay)
    result = ofswitch.add_modify_flow(flow_entry4)
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print ("<<< Flow successfully added to the Controller")
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.detailed())
        delete_flows(ofswitch, table_id, range(first_flow_id, flow_id+1))
        exit(0)

    print ("\n")
    print ("<<< Get configured flows from the Controller")
    time.sleep(rundelay)
    for i in range(first_flow_id, flow_id+1):
        result = ofswitch.get_configured_flow(table_id, i)
        status = result.get_status()
        if(status.eq(STATUS.OK)):
            print ("<<< Flow '%s' successfully read from the Controller" % i)
            print ("Flow info:")
            flow = result.get_data()
            print json.dumps(flow, indent=4)
        else:
            print ("\n")
            print ("!!!Demo terminated, reason: %s" % status.detailed())
            delete_flows(ofswitch, table_id, range(first_flow_id, flow_id+1))
            exit(0)

    print ("\n")
    print ("<<< Delete flows from the Controller's cache "
           "and from the table '%s' on the '%s' node" % (table_id, nodeName))
    time.sleep(rundelay)
    delete_flows(ofswitch, table_id, range(first_flow_id, flow_id+1))

    print ("\n")
    print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
    print (">>> Demo End")
    print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
Esempio n. 5
0
def of_demo_15():
    f = "cfg.yml"
    d = {}
    if(load_dict_from_file(f, d) is False):
        print("Config file '%s' read error: " % f)
        exit()

    try:
        ctrlIpAddr = d['ctrlIpAddr']
        ctrlPortNum = d['ctrlPortNum']
        ctrlUname = d['ctrlUname']
        ctrlPswd = d['ctrlPswd']
        nodeName = d['nodeName']
        rundelay = d['rundelay']
    except:
        print ("Failed to get Controller device attributes")
        exit(0)

    print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
    print ("<<< Demo 15 Start")
    print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")

    ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd)
    ofswitch = OFSwitch(ctrl, nodeName)

    # --- Flow Match: Ethernet Type
    #                 VLAN ID
    #                 Input Port
    eth_type = ETH_TYPE_IPv4
    vlan_id = 100
    input_port = 3

    # --- Flow Actions: Push VLAN: Ethernet Type
    #                   Set Field: VLAN ID
    #                   Output:    Port Number
    push_eth_type = ETH_TYPE_DOT1AD  # 802.1ad VLAN tagged frame
    push_vlan_id = 200
    output_port = 5

    print ("<<< 'Controller': %s, 'OpenFlow' switch: '%s'" %
           (ctrlIpAddr, nodeName))

    print "\n"
    print ("<<< Set OpenFlow flow on the Controller")
    print ("        Match:  Ethernet Type (%s)\n"
           "                VLAN ID (%s)\n"
           "                Input Port (%s)" %
           (hex(eth_type), vlan_id, input_port))
    print ("        Action: Push VLAN (Ethernet Type=%s)" %
           (hex(push_eth_type)))
    print ("                Set Field (VLAN ID=%s)" %
           (push_vlan_id))
    print ("                Output (to Physical Port Number %s)" %
           (output_port))

    time.sleep(rundelay)

    flow_entry = FlowEntry()
    flow_entry.set_flow_name(flow_name="Push VLAN")
    table_id = 0
    flow_entry.set_flow_table_id(table_id)
    flow_id = 22
    flow_entry.set_flow_id(flow_id)
    flow_entry.set_flow_priority(flow_priority=1013)
    flow_entry.set_flow_cookie(cookie=407)
    flow_entry.set_flow_cookie_mask(cookie_mask=255)
    flow_entry.set_flow_hard_timeout(hard_timeout=3400)
    flow_entry.set_flow_idle_timeout(idle_timeout=3400)

    # --- Instruction: 'Apply-actions'
    #     Actions:     'PushVlan'
    #                  'SetField'
    #                  'Output'
    instruction = Instruction(instruction_order=0)
    action = PushVlanHeaderAction(order=0)
    action.set_eth_type(eth_type=push_eth_type)
    instruction.add_apply_action(action)
    action = SetFieldAction(order=1)
    action.set_vlan_id(vid=push_vlan_id)
    instruction.add_apply_action(action)
    action = OutputAction(order=2, port=output_port)
    instruction.add_apply_action(action)
    flow_entry.add_instruction(instruction)

    # --- Match Fields: Ethernet Type
    #                   Ethernet Source Address
    #                   Ethernet Destination Address
    #                   Input Port
    match = Match()
    match.set_eth_type(eth_type)
    match.set_vlan_id(vlan_id)
    match.set_in_port(in_port=input_port)
    flow_entry.add_match(match)

    print ("\n")
    print ("<<< Flow to send:")
    print flow_entry.get_payload()
    time.sleep(rundelay)
    result = ofswitch.add_modify_flow(flow_entry)
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print ("<<< Flow successfully added to the Controller")
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        exit(0)

    print ("\n")
    print ("<<< Get configured flow from the Controller")
    time.sleep(rundelay)
    result = ofswitch.get_configured_flow(table_id, flow_id)
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print ("<<< Flow successfully read from the Controller")
        print ("Flow info:")
        flow = result.get_data()
        print json.dumps(flow, indent=4)
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        exit(0)

    print ("\n")
    print ("<<< Delete flow with id of '%s' from the Controller's cache "
           "and from the table '%s' on the '%s' node" %
           (flow_id, table_id, nodeName))
    time.sleep(rundelay)
    result = ofswitch.delete_flow(flow_entry.get_flow_table_id(),
                                  flow_entry.get_flow_id())
    status = result.get_status()
    if(status.eq(STATUS.OK)):
        print ("<<< Flow successfully removed from the Controller")
    else:
        print ("\n")
        print ("!!!Demo terminated, reason: %s" % status.brief().lower())
        exit(0)

    print ("\n")
    print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
    print (">>> Demo End")
    print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
Esempio n. 6
0
def of_demo_25():
    f = "cfg.yml"
    d = {}
    if (load_dict_from_file(f, d) is False):
        print("Config file '%s' read error: " % f)
        exit()

    try:
        ctrlIpAddr = d['ctrlIpAddr']
        ctrlPortNum = d['ctrlPortNum']
        ctrlUname = d['ctrlUname']
        ctrlPswd = d['ctrlPswd']
        nodeName = d['nodeName']
        rundelay = d['rundelay']
    except:
        print("Failed to get Controller device attributes")
        exit(0)

    print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
    print("<<< Demo 25 Start")
    print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")

    ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd)
    ofswitch = OFSwitch(ctrl, nodeName)

    table_id = 0
    priority = 500
    cookie = 1000
    cookie_mask = 255
    customer_port = 110
    provider_port = 111
    qinq_eth_type = ETH_TYPE_STAG  # 802.1ad (QinQ) VLAN tagged frame
    dot1q_eth_type = ETH_TYPE_CTAG  # 802.1q VLAN tagged frame
    arp_eth_type = ETH_TYPE_ARP
    ip_eth_type = ETH_TYPE_IPv4
    provider_vlan_id = 100  # Provider VLAN
    customer_vlan_id = 998  # Customer VLAN
    first_flow_id = 31

    print("<<< 'Controller': %s, 'OpenFlow' switch: '%s'" %
          (ctrlIpAddr, nodeName))

    # ---------------------------------------------------
    # First flow entry
    # ---------------------------------------------------
    print "\n"
    print("<<< Set OpenFlow flow on the Controller")
    print(
        "        Match:  Ethernet Type (%s)\n"
        "                VLAN ID (%s)\n"
        "                Input Port (%s)" %
        (hex(arp_eth_type), customer_vlan_id, customer_port))
    print(
        "        Action: Push VLAN (Ethernet Type %s)\n"
        "                Set Field (VLAN ID %s)\n"
        "                Push VLAN (Ethernet Type %s)\n"
        "                Set Field (VLAN ID %s)\n"
        "                Output (Physical Port number %s)" %
        (hex(qinq_eth_type), provider_vlan_id, hex(dot1q_eth_type),
         customer_vlan_id, provider_port))

    time.sleep(rundelay)

    flow_id = first_flow_id
    flow_entry1 = FlowEntry()
    flow_entry1.set_flow_table_id(table_id)
    fname = "[MLX1-A] Test flow (match:inport=110,arp;" + \
            "actions:push-QINQ-tag,mod_vlan=100," + \
            "push-DOT1Q-tag,mod_vlan=998,output:111)"
    flow_entry1.set_flow_name(flow_name=fname)
    flow_entry1.set_flow_id(flow_id)
    flow_entry1.set_flow_hard_timeout(hard_timeout=600)
    flow_entry1.set_flow_idle_timeout(idle_timeout=300)
    flow_entry1.set_flow_priority(priority)
    flow_entry1.set_flow_cookie(cookie)
    flow_entry1.set_flow_cookie_mask(cookie_mask)

    instruction = Instruction(instruction_order=0)

    action_order = 0
    action = PushVlanHeaderAction(action_order)
    action.set_eth_type(qinq_eth_type)
    instruction.add_apply_action(action)

    action_order += 1
    action = SetFieldAction(action_order)
    action.set_vlan_id(provider_vlan_id)
    instruction.add_apply_action(action)

    action_order += 1
    action = PushVlanHeaderAction(action_order)
    action.set_eth_type(dot1q_eth_type)
    instruction.add_apply_action(action)

    action_order += 1
    action = SetFieldAction(action_order)
    action.set_vlan_id(customer_vlan_id)
    instruction.add_apply_action(action)

    action_order += 1
    action = OutputAction(action_order, provider_port)
    instruction.add_apply_action(action)

    flow_entry1.add_instruction(instruction)

    match = Match()

    match.set_eth_type(arp_eth_type)
    match.set_vlan_id(customer_vlan_id)
    match.set_in_port(in_port=customer_port)

    flow_entry1.add_match(match)

    print("\n")
    print("<<< Flow to send:")
    print flow_entry1.get_payload()
    time.sleep(rundelay)
    result = ofswitch.add_modify_flow(flow_entry1)
    status = result.get_status()
    if (status.eq(STATUS.OK)):
        print("<<< Flow successfully added to the Controller")
    else:
        print("\n")
        print("!!!Demo terminated, reason: %s" % status.detailed())
        delete_flows(ofswitch, table_id, range(first_flow_id, flow_id + 1))
        exit(0)

    # ---------------------------------------------------
    # Second flow entry
    # ---------------------------------------------------
    print "\n"
    print("<<< Set OpenFlow flow on the Controller")
    print(
        "        Match:  Ethernet Type (%s)\n"
        "                VLAN ID (%s)\n"
        "                Input Port (%s)" %
        (hex(ip_eth_type), customer_vlan_id, customer_port))
    print(
        "        Action: Push VLAN (Ethernet Type %s)\n"
        "                Set Field (VLAN ID %s)\n"
        "                Push VLAN (Ethernet Type %s)\n"
        "                Set Field (VLAN ID %s)\n"
        "                Output (Physical Port number %s)" %
        (hex(qinq_eth_type), provider_vlan_id, hex(dot1q_eth_type),
         customer_vlan_id, provider_port))

    time.sleep(rundelay)

    flow_id += 1
    flow_entry2 = FlowEntry()
    flow_entry2.set_flow_table_id(table_id)
    fname = "[MLX1-A] Test flow (match:inport=110,ip;" + \
            "actions:push-QINQ-tag,mod_vlan=100,output:111)"
    flow_entry2.set_flow_name(flow_name=fname)
    flow_entry2.set_flow_id(flow_id)
    flow_entry2.set_flow_hard_timeout(hard_timeout=600)
    flow_entry2.set_flow_idle_timeout(idle_timeout=300)
    flow_entry2.set_flow_priority(priority)
    flow_entry2.set_flow_cookie(cookie)
    flow_entry2.set_flow_cookie_mask(cookie_mask)

    instruction = Instruction(instruction_order=0)

    action_order = 0
    action = PushVlanHeaderAction(action_order)
    action.set_eth_type(qinq_eth_type)
    instruction.add_apply_action(action)

    action_order += 1
    action = SetFieldAction(action_order)
    action.set_vlan_id(provider_vlan_id)
    instruction.add_apply_action(action)

    action_order += 1
    action = PushVlanHeaderAction(action_order)
    action.set_eth_type(dot1q_eth_type)
    instruction.add_apply_action(action)

    action_order += 1
    action = SetFieldAction(action_order)
    action.set_vlan_id(customer_vlan_id)
    instruction.add_apply_action(action)

    action_order += 1
    action = OutputAction(action_order, provider_port)
    instruction.add_apply_action(action)

    flow_entry2.add_instruction(instruction)

    match = Match()

    match.set_eth_type(ip_eth_type)
    match.set_vlan_id(customer_vlan_id)
    match.set_in_port(in_port=customer_port)

    flow_entry2.add_match(match)

    print("\n")
    print("<<< Flow to send:")
    print flow_entry2.get_payload()
    time.sleep(rundelay)
    result = ofswitch.add_modify_flow(flow_entry2)
    status = result.get_status()
    if (status.eq(STATUS.OK)):
        print("<<< Flow successfully added to the Controller")
    else:
        print("\n")
        print("!!!Demo terminated, reason: %s" % status.detailed())
        delete_flows(ofswitch, table_id, range(first_flow_id, flow_id + 1))
        exit(0)

    # ---------------------------------------------------
    # Third flow entry
    # ---------------------------------------------------
    print "\n"
    print("<<< Set OpenFlow flow on the Controller")
    print(
        "        Match:  Ethernet Type (%s)\n"
        "                VLAN ID (%s)\n"
        "                Input Port (%s)" %
        (hex(arp_eth_type), provider_vlan_id, provider_port))
    print(
        "        Action: Pop VLAN\n"
        "                Output (Physical Port number %s)" % (customer_port))

    time.sleep(rundelay)

    flow_id += 1
    flow_entry3 = FlowEntry()
    flow_entry3.set_flow_table_id(table_id)
    fname = "[MLX1-A] Test flow (match:inport=111,arp,vid=100;" + \
            "actions:pop-vlan-tag,output=110)"
    flow_entry3.set_flow_name(flow_name=fname)
    flow_entry3.set_flow_id(flow_id)
    flow_entry3.set_flow_hard_timeout(hard_timeout=600)
    flow_entry3.set_flow_idle_timeout(idle_timeout=300)
    flow_entry3.set_flow_priority(priority)
    flow_entry3.set_flow_cookie(cookie)
    flow_entry3.set_flow_cookie_mask(cookie_mask)

    instruction = Instruction(instruction_order=0)

    action_order = 0
    action = PopVlanHeaderAction(action_order)
    instruction.add_apply_action(action)

    action_order += 1
    action = OutputAction(action_order, customer_port)
    instruction.add_apply_action(action)

    flow_entry3.add_instruction(instruction)

    match = Match()
    match.set_eth_type(arp_eth_type)
    match.set_vlan_id(provider_vlan_id)
    match.set_in_port(provider_port)

    flow_entry3.add_match(match)

    print("\n")
    print("<<< Flow to send:")
    print flow_entry3.get_payload()
    time.sleep(rundelay)
    result = ofswitch.add_modify_flow(flow_entry3)
    status = result.get_status()
    if (status.eq(STATUS.OK)):
        print("<<< Flow successfully added to the Controller")
    else:
        print("\n")
        print("!!!Demo terminated, reason: %s" % status.detailed())
        delete_flows(ofswitch, table_id, range(first_flow_id, flow_id + 1))
        exit(0)

    # ---------------------------------------------------
    # Fourth flow entry
    # ---------------------------------------------------
    print "\n"
    print("<<< Set OpenFlow flow on the Controller")
    print(
        "        Match:  Ethernet Type (%s)\n"
        "                VLAN ID (%s)\n"
        "                Input Port (%s)" %
        (hex(ip_eth_type), provider_vlan_id, provider_port))
    print(
        "        Action: Pop VLAN\n"
        "                Output (Physical Port number %s)" % (customer_port))

    time.sleep(rundelay)

    flow_id += 1
    flow_entry4 = FlowEntry()
    flow_entry4.set_flow_table_id(table_id)
    flow_entry4.set_flow_id(flow_id)
    fname = "[MLX1-A] Test flow (match:inport=111,ip,vid=100;" + \
            "actions:pop-vlan-tag,output=110)"
    flow_entry4.set_flow_name(flow_name=fname)
    flow_entry4.set_flow_hard_timeout(hard_timeout=600)
    flow_entry4.set_flow_idle_timeout(idle_timeout=300)
    flow_entry4.set_flow_priority(priority)
    flow_entry4.set_flow_cookie(cookie)
    flow_entry4.set_flow_cookie_mask(cookie_mask)

    instruction = Instruction(instruction_order=0)

    action_order = 0
    action = PopVlanHeaderAction(action_order)
    instruction.add_apply_action(action)

    action_order += 1
    action = OutputAction(action_order, customer_port)
    instruction.add_apply_action(action)

    flow_entry4.add_instruction(instruction)

    match = Match()
    match.set_eth_type(ip_eth_type)
    match.set_vlan_id(provider_vlan_id)
    match.set_in_port(provider_port)

    flow_entry4.add_match(match)

    print("\n")
    print("<<< Flow to send:")
    print flow_entry4.get_payload()
    time.sleep(rundelay)
    result = ofswitch.add_modify_flow(flow_entry4)
    status = result.get_status()
    if (status.eq(STATUS.OK)):
        print("<<< Flow successfully added to the Controller")
    else:
        print("\n")
        print("!!!Demo terminated, reason: %s" % status.detailed())
        delete_flows(ofswitch, table_id, range(first_flow_id, flow_id + 1))
        exit(0)

    print("\n")
    print("<<< Get configured flows from the Controller")
    time.sleep(rundelay)
    for i in range(first_flow_id, flow_id + 1):
        result = ofswitch.get_configured_flow(table_id, i)
        status = result.get_status()
        if (status.eq(STATUS.OK)):
            print("<<< Flow '%s' successfully read from the Controller" % i)
            print("Flow info:")
            flow = result.get_data()
            print json.dumps(flow, indent=4)
        else:
            print("\n")
            print("!!!Demo terminated, reason: %s" % status.detailed())
            delete_flows(ofswitch, table_id, range(first_flow_id, flow_id + 1))
            exit(0)

    print("\n")
    print(
        "<<< Delete flows from the Controller's cache "
        "and from the table '%s' on the '%s' node" % (table_id, nodeName))
    time.sleep(rundelay)
    delete_flows(ofswitch, table_id, range(first_flow_id, flow_id + 1))

    print("\n")
    print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
    print(">>> Demo End")
    print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
Esempio n. 7
0
 
 flow_id = first_flow_id
 flow_entry1 = FlowEntry()
 flow_entry1.set_flow_table_id(table_id)
 flow_entry1.set_flow_name(flow_name = "[MLX1-A] Test flow (match:inport=110,arp;actions:push-QINQ-tag,mod_vlan=100,push-DOT1Q-tag,mod_vlan=998,output:111)")
 flow_entry1.set_flow_id(flow_id)
 flow_entry1.set_flow_hard_timeout(hard_timeout = 600)
 flow_entry1.set_flow_idle_timeout(idle_timeout = 300)
 flow_entry1.set_flow_priority(priority)
 flow_entry1.set_flow_cookie(cookie)
 flow_entry1.set_flow_cookie_mask(cookie_mask)
 
 instruction = Instruction(instruction_order = 0)
 
 action_order = 0
 action = PushVlanHeaderAction(action_order)
 action.set_eth_type(qinq_eth_type)
 instruction.add_apply_action(action)
 
 action_order += 1
 action = SetFieldAction(action_order)
 action.set_vlan_id(provider_vlan_id)
 instruction.add_apply_action(action)
 
 action_order += 1
 action = PushVlanHeaderAction(action_order)
 action.set_eth_type(dot1q_eth_type)
 instruction.add_apply_action(action)
 
 action_order += 1
 action = SetFieldAction(action_order)