Example #1
0
def installPathFlows(macHostA, macHostB, pathA2B):
    ##### YOUR CODE HERE #####
    #flow=ryu_ofctl.FlowEntry()
    for x in range(0, len(pathA2B)):
        flow = ryu_ofctl.FlowEntry()
        act = ryu_ofctl.OutputAction(pathA2B[x]['out_port'])
        flow.in_port = pathA2B[x]['in_port']
        flow.addAction(act)
        dpid = pathA2B[x]['dpid']
        #print dpid
        #print pathA2B[x]['in_port']
        #print pathA2B[x]['out_port']
        ryu_ofctl.insertFlow(dpid, flow)

    for x in reversed(range(0, len(pathA2B))):
        flow = ryu_ofctl.FlowEntry()
        act = ryu_ofctl.OutputAction(pathA2B[x]['in_port'])
        flow.in_port = pathA2B[x]['out_port']
        flow.addAction(act)
        dpid = pathA2B[x]['dpid']
        ryu_ofctl.insertFlow(dpid, flow)

    print "installed"

    return
Example #2
0
def createFlow(dl_src, dl_dst, in_port, out_port, switch_dpid, priority=50001):
    """
    create the flow and insert to the switch
    :param dl_src: source mac, string
    :param dl_dst: dest mac, string
    :param in_port: in port, integer
    :param out_port: out port for the action, integer
    :return: the FlowEntry object with the associate action of out_port
    """
    flow = ryu_ofctl.FlowEntry()
    # for the constant
    flow.priority = priority
    # http protocol: tcp and port 80
    flow.dl_type = 0x800  # IPV4
    flow.nw_proto = 0x6 # TCP
    flow.tp_dst = 80 # webserver port
    # for src and dest mac
    flow.dl_src = dl_src
    flow.dl_dst = dl_dst
    # for in and out_port
    flow.in_port = in_port
    act = ryu_ofctl.OutputAction(out_port)
    # add the action to the flow
    flow.addAction(act)
    # insert the flow to the switch
    print("the flow is")
    flow.printMatch()
    print(ryu_ofctl.insertFlow(switch_dpid, flow))
    return flow
Example #3
0
def installPathFlows(macHostA, macHostB, pathA2B):
    for link in pathA2B:
        flow1 = ryu.FlowEntry()
        flow2 = ryu.FlowEntry()
        #print link
        action1 = ryu.OutputAction(link['out_port'])
        action2 = ryu.OutputAction(link['in_port'])

        flow1.in_port = link['in_port']
        flow2.in_port = link['out_port']

        flow1.addAction(action1)
        flow2.addAction(action2)

        ryu.insertFlow(str(link['dpid']), flow1)
        ryu.insertFlow(str(link['dpid']), flow2)

    print "added flows"
    return
Example #4
0
import ryu_ofctl

flow = ryu_ofctl.FlowEntry()
act = ryu_ofctl.OutputAction(2)
flow.in_port = 1
flow.dl_dst = "00:00:00:00:00:02"
flow.addAction(act)
dpid2 = 1
ryu_ofctl.insertFlow(dpid2, flow)
act1 = ryu_ofctl.OutputAction(1)
act2 = ryu_ofctl.OutputAction(3)
flow.in_port = 2
flow.addAction(act2)
flow.addAction(act1)
dpid3 = 1
ryu_ofctl.insertFlow(dpid3, flow)
Example #5
0
import ryu_ofctl
flow1 = ryu_ofctl.FlowEntry()
flow2 = ryu_ofctl.FlowEntry()
flow3 = ryu_ofctl.FlowEntry()

output_1 = ryu_ofctl.OutputAction(1)
output_2 = ryu_ofctl.OutputAction(2)
output_3 = ryu_ofctl.OutputAction(3)


flow1.in_port = 1
flow3.in_port = 3

flow1.addAction(output_2)
flow3.addAction(output_2)

flow2.addAction(output_1)
flow2.addAction(output_3)

dpid = '1'

ryu_ofctl.insertFlow(dpid, flow1)
ryu_ofctl.insertFlow(dpid, flow3)
#ryu_ofctl.insertFlow(dpid, flow2)
Example #6
0
#marinette - march 28, 2019

import ryu_ofctl
dpid = '1'  # '0x1' or '0000000000000001' works as well

#Deleting flows
ryu_ofctl.deleteAllFlows(dpid)
print("Deleted all flows.")
flow = ryu_ofctl.FlowEntry()
flow2 = ryu_ofctl.FlowEntry()
flow3 = ryu_ofctl.FlowEntry()
flow4 = ryu_ofctl.FlowEntry()
act = ryu_ofctl.OutputAction(2)

flow.in_port = 1
flow.dl_dst = "00:00:00:00:00:03"

flow2.in_port = 1
flow2.dl_dst = "00:00:00:00:00:02"
flow2.addAction(act)

flow3.in_port = 3
flow3.dl_dst = "00:00:00:00:00:01"

flow4.in_port = 3
flow4.dl_dst = "00:00:00:00:00:02"
flow4.addAction(act)

ryu_ofctl.insertFlow(dpid, flow)
ryu_ofctl.insertFlow(dpid, flow2)
ryu_ofctl.insertFlow(dpid, flow3)
Example #7
0
import ryu_ofctl as ryu

dpid = 1
ryu.deleteAllFlows(dpid)

flow = ryu.FlowEntry()
act1 = ryu.OutputAction(1)
act2 = ryu.OutputAction(2)

flow.in_port = 3
flow.addAction(act1)
flow.addAction(act2)
ryu.insertFlow(dpid, flow)

flow2 = ryu.FlowEntry()
act3 = ryu.OutputAction(3)
act4 = ryu.OutputAction(2)

flow2.in_port = 1
flow2.addAction(act3)
flow2.addAction(act4)
ryu.insertFlow(dpid, flow2)
Example #8
0
import ryu_ofctl as ryu

dpid = 1
ryu.deleteAllFlows(dpid)

flow = ryu.FlowEntry()
act1 = ryu.OutputAction(2)

flow.in_port = 3
flow.addAction(act1)
ryu.insertFlow(dpid, flow)

flow2 = ryu.FlowEntry()
act2 = ryu.OutputAction(2)

flow2.in_port = 3
flow2.addAction(act2)
ryu.insertFlow(dpid, flow2)