The event object also has a .dpid attribute which you can use to distinguish
between switches -- each switch has a different DPID.
So you'll want to do something along the lines of...
if event.dpid == <DPID of switch 1>:
if packet.find('tcp'):
action = of.ofp_action_enqueue(port = port, queue_id = 3)
...
elif event.dpid == <DPID of switch 2>:
if packet.find('tcp'):
action = of.ofp_action_enqueue(port = port, queue_id = 2) # different queue
on this switch
...
else:
# This switch doesn't have any queues -- just use output
action = of.ofp_action_output(port = port)
...
msg.actions.append(action)
Hope that helps.
-- Murphy
On Apr 13, 2013, at 3:19 PM, Sayed Qaiser Ali Shah Shah wrote:
> First of all I created two queues i.e. queue-0 and queue-1 on PORT Eth-1 of
> OVS. I use the code below on cotroller
> if packet.find('tcp'):
> queue=1
> elif packet.find('arp'):
> queue=0
> else:
> queue=1
> msg = of.ofp_flow_mod()
> msg.match = of.ofp_match.from_packet(packet, event.port)
> msg.idle_timeout = 10
> msg.hard_timeout = 30
> msg.actions.append(of.ofp_action_enqueue(port = port, queue_id = queue))
> msg.data = event.ofp # 6a
> self.connection.send(msg)
> When I use the mininet command "iperf h1 h2" it worked fine and showed less
> bandwidth because I allocated less bandwidth to queues. But when I iperf
> host-2 and host-3 "iperf h2 h3" as the traffic doesn't pass via eth-1 the
> bandwidth was expected to be high which is by default, but it showed much
> less bandwidth than "iperf h1 h2". This is because as when traffic was
> checked and matched it assigns 1 to queue i.e. queue=1 and as there is not
> such queue available on port h2 or h3 it showed wrong result. How to make it
> work correctly i.e. if queues are not created on an interface then queues
> should not be checked and should not be assigned to traffic.
>
> On Fri, Apr 5, 2013 at 1:42 PM, Sayed Qaiser Ali Shah Shah
> <[email protected]> wrote:
> Thanks a lot. In fact I want the same thing which you mentioned and I was
> after this since last one month. I am using OVS switch. I will try this. This
> is of great help for me.
>
>
> On Fri, Apr 5, 2013 at 1:18 PM, Murphy McCauley <[email protected]>
> wrote:
> Yes, you can do this if what you want can be accomplished using the queue
> types available in your switch. If that condition is true, then there are
> several ways to do it with different tradeoffs. I'd suggest that you start
> off by modifying the l2_learning component to assign each new flow to the
> appropriate queue based on your criteria (e.g., protocol number). To do this
> you:
>
> 1) Configure queues on your switch. How you do this is switch-specific and
> not part of OpenFlow. There's an article on how to configure some queues in
> Open vSwitch here (or read the OVS documentation for more):
> http://openvswitch.org/support/config-cookbooks/qos-rate-limiting/
>
> If you're not using OVS, you'll have to consult your switch's documentation.
>
> When you set up the queues, each of them will have an integer ID. You can
> use the OpenFlow enqueue action to direct traffic to these queues.
>
> 2) Modify l2_learning's flow installation. Starting around line 169 in
> l2_learning.py, it creates new flow entries with an ofp_action_output action.
> You'd change this in two ways. First, you'd decide which queue you wanted
> by inspecting the packet. This is available in the .parsed attribute of the
> PacketIn event object, as I mentioned earlier. For example, an easy way to
> determine if the packet is ipv4 is just "if event.parsed.find('ipv4'): ...".
> Once you determine which queue to assign to, use the ofp_action_enqueue
> action instead of ofp_action_output. Altogether, this makes the modified
> code look something like this:
>
> log.debug("installing flow for %s.%i -> %s.%i" %
> (packet.src, event.port, packet.dst, port))
>
> if packet.find('tcp'):
> queue = 1 # TCP goes to queue 1
> elif packet.find('ipv4'):
> queue = 2 # IP that isn't TCP goes to queue 2
> else:
> queue = 3 # All other traffic goes to queue 3
>
> msg = of.ofp_flow_mod()
> msg.match = of.ofp_match.from_packet(packet, event.port)
> msg.idle_timeout = 10
> msg.hard_timeout = 30
> msg.actions.append(of.ofp_action_enqueue(port = port, queue_id = queue))
> msg.data = event.ofp # 6a
> self.connection.send(msg)
>
>
> Hope that helps.
>
> -- Murphy
>
> On Apr 5, 2013, at 12:58 AM, Sayed Qaiser Ali Shah Shah wrote:
>
>> I think you mean that I want to achieve from this. I want to get IP protocol
>> number from packet and then on the basis of that protocol number I want to
>> assign bandwidth to flows/hosts on the basis of their needs. Like the
>> protocol number which needs high bandwidth should be allocated high
>> bandwidth or the one which needs less bandwidth should be allocated less
>> bandwidth so, that bandwidth doesn't waste. I am doing this for end user
>> satisfaction. This is related to QoS.
>> Am I on Right direction? Can I do this?
>>
>> On Fri, Apr 5, 2013 at 5:36 AM, Murphy McCauley <[email protected]>
>> wrote:
>> On Apr 4, 2013, at 4:08 PM, Sayed Qaiser Ali Shah Shah wrote:
>>> The link which you provide was very helpful and I found match class in that
>>> and I use this code
>>>
>>> import pox.openflow.libopenflow_01 as of # POX convention
>>> import pox.lib.packet as pkt # POX convention
>>> my_match = of.ofp_match(dl_type = pkt.ethernet.IP_TYPE, nw_proto =
>>> pkt.ipv4.TCP_PROTOCOL, tp_dst = 80)
>>>
>>> Which will create match to web servers but I don't know how this will work.
>>> Will it work automatically i.e. it will forward packets to server
>>> automatically when any packet having nw_proto=TCP_Protocol and tp_dst=80.
>>> If it does not forward the packet automatically then how it works?
>>
>> You still haven't really explained what it is that you're trying to do.
>> What is your high-level goal? Are you trying to install flow table entries?
>> Do you want packets from particular flows sent to the controller? Are you
>> trying to block certain connections?
>>
>> If you're trying to install flow entries on the switch, you need to send an
>> ofp_flow_mod (as per the OpenFlow spec). This contains a match object and
>> then contains actions to tell the switch what to do with it (send it out of
>> a port, send it to the controller, etc.). See the section of the manual
>> wiki on ofp_flow_mod, as well as the examples in the forwarding directory of
>> POX (for example, l2_learning).
>>
>> -- Murphy
>>
>>
>>
>> --
>> Regards
>>
>> Sayed Qaiser Ali Shah
>> MSIT-12
>> NUST (SEECS)
>
>
>
>
> --
> Regards
>
> Sayed Qaiser Ali Shah
> MSIT-12
> NUST (SEECS)
>
>
>
> --
> Regards
>
> Sayed Qaiser Ali Shah
> MSIT-12
> NUST (SEECS)