<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">What you're doing wrong is not clear in the OpenFlow 1.0 spec. 1.0.1 clarified it, and Open vSwitch's documentation is also fairly clear on the subject.<div><br></div><div>Matches have prerequisites. Basically, you can't match on something from a deeper layer without matching on the appropriate thing in the shallower layer first. So, for example, you can't match on fields in an IP header without first matching that the Ethernet frame type is actually IP. Similarly, you can't match on TCP or UDP port numbers without first specifying that the IP protocol is TCP or UDP.</div><div><br></div><div>In your case, this means your match also needs to match for dl_type = pkt.ethernet.IP_TYPE (0x0800), and nw_proto = pkt.ipv4.TCP_PROTOCOL.</div><div><br></div><div>-- Murphy</div><div><div><div><br><div><div>On May 20, 2013, at 12:00 PM, Alex wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><meta http-equiv="Content-Type" content="text/html charset=us-ascii"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hello everyone.<div><br></div><div>I'm using MIninet 2.0, POX and Open vSwitch, and I try to implement NAT/PAT function in switch. But I faced with one problem: when I send ofp_flow_mod message, like this:</div><div><br></div><div><div><i>ip_packet = packet.payload</i></div><div><i>tcp_packet = ip_packet.payload</i></div><div><i>new_src_port = random.randint(4096, 65533)</i></div></div><div><br></div><div><div><i>back_msg = of.ofp_flow_mod()</i></div><div><i>back_msg.cookie = 12</i></div><div><i>back_msg.match.in_port = port</i></div><div><i>back_msg.match.nw_dst = IPAddr("10.0.2.1") </i></div><div><i>back_msg.match.tp_dst = new_src_port</i></div><div><i>back_msg.actions.append(of.ofp_action_output(port = event.port))</i></div><div><i>back_msg.actions.append(of.ofp_action_nw_addr.set_dst(ip_packet.srcip))</i></div><div><i>back_msg.actions.append(of.ofp_action_tp_port.set_dst(tcp_packet.srcport))</i></div><div><i>back_msg.idle_timeout = 120</i></div><div><i>self.connection.send(back_msg)</i></div></div><div><i><br></i></div><div>and then I check flow with command:</div><div> <i>ovs-ofctl dump-flows tcp:127.0.0.1:6635</i></div><div><i><br></i></div><div>And the only flow with cookie = 12 has only 1 match field instead of 3, that I specify in match structure, but all actions are correct:</div><div><br></div><div>cookie=0xc, duration=5.999s, table=0, n_packets=6, n_bytes=1637, idle_timeout=120,in_port=2 actions=output:1,mod_nw_dst:10.0.1.1,mod_tp_dst:57830</div><div><br></div><div>I've added log.debug message, that could help to find problem, but it looks ok:</div><div><i>log.debug('Back message with match structure: port - %i, IP-dest - %s, TCP-port dst - %i' % (port, back_msg.match.nw_dst, back_msg.match.tp_dst))</i></div><div><br></div><div>DEBUG:ext.lab_4:Back message with match structure: port - 2, IP-dest - 10.0.2.1, TCP-port dst - 51920</div><div><br></div><div>I send one more ofp_flow_mod message in the same event handler, but I use ofp_match.from_packet() method and it works fine.</div><div><br></div><div>Thanks,</div><div>Alex.</div></div></blockquote></div><br></div></div></div></body></html>