Hi,
> The code is below. I can't do what i want.
>
> what should i do ?
Your code insufficient the match condition.
Please add eth_type to the match condition.
match1 = parser.OFPMatch(eth_type=0x0800,
in_port=3,
eth_dst="00:00:00:00:00:01")
There is pre-requisite for the match field,it correlate with actions.
Your code has set destination IPv4 address at OFPActionSetField.
So, you must add eth_type to the match condition.
actions_modify_headers = [
parser.OFPActionSetField(eth_dst="00:00:00:00:00:03"),
parser.OFPActionSetField(ipv4_dst="10.1.1.2"),
parser.OFPActionOutput(2)]
Regards, Muraoka
On 2017年01月09日 01:12, Alan Wang wrote:
> Hi All,
>
> I tried to modify the packet header (destination ip and mac) and forward
> the
>
> packet to the new destination (modified packet header about destination
> ip and
>
> mac).
>
> The code is below. I can't do what i want.
>
> what should i do ?
>
> def add_flow(self, datapath, priority, match, actions, buffer_id=None):
> ofproto = datapath.ofproto
> parser = datapath.ofproto_parser
>
> inst = [parser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS,
> actions)]
> if buffer_id:
> mod = parser.OFPFlowMod(datapath=datapath, buffer_id=buffer_id,
> priority=priority, match=match,
> instructions=inst)
> else:
> mod = parser.OFPFlowMod(datapath=datapath, priority=priority,
> match=match, instructions=inst)
> datapath.send_msg(mod)
>
> @set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
> def _packet_in_handler(self, ev):
> if ev.msg.msg_len < ev.msg.total_len:
> self.logger.debug("packet truncated: only %s of %s bytes",
> ev.msg.msg_len, ev.msg.total_len)
> msg = ev.msg
> datapath = msg.datapath
> ofproto = datapath.ofproto
> parser = datapath.ofproto_parser
> in_port = msg.match['in_port']
>
> pkt = packet.Packet(msg.data)
> eth = pkt.get_protocols(ethernet.ethernet)[0]
> ip4_pkt = pkt.get_protocol(ipv4.ipv4)
>
> if eth.ethertype == ether_types.ETH_TYPE_LLDP:
> # ignore lldp packet
> return
> dst = eth.dst
> src = eth.src
>
>
> dpid = datapath.id <http://datapath.id>
> self.mac_to_port.setdefault(dpid, {})
>
> self.logger.info <http://self.logger.info>("packet in %s %s %s
> %s", dpid, src, dst, in_port)
>
> # learn a mac address to avoid FLOOD next time.
> self.mac_to_port[dpid][src] = in_port
>
> if eth.ethertype == ether_types.ETH_TYPE_ARP:
> print("Yes, ARP Packet!!")
>
> else:
> print("NO!!")
> print(ip4_pkt.dst)
> print(ip4_pkt.src)
>
> #modify packet header
> actions_modify_headers =
> [parser.OFPActionSetField(eth_dst="00:00:00:00:00:03"),
> parser.OFPActionSetField
>
> (ipv4_dst="10.1.1.2"),parser.OFPActionOutput(2)]
> match1 = parser.OFPMatch(in_port=3, eth_dst="00:00:00:00:00:01")
>
> self.add_flow(datapath, 1, match1, actions_modify_headers)
>
> out = parser.OFPPacketOut(datapath=datapath,
> buffer_id=msg.buffer_id,
> in_port=in_port, actions=actions,
> data=data)
> datapath.send_msg(out)
>
>
>
> if dst in self.mac_to_port[dpid]:
> out_port = self.mac_to_port[dpid][dst]
>
>
> else:
> out_port = ofproto.OFPP_FLOOD
>
> actions = [parser.OFPActionOutput(out_port)]
>
> # install a flow to avoid packet_in next time
> if out_port != ofproto.OFPP_FLOOD:
> match = parser.OFPMatch(in_port=in_port, eth_dst=dst)
> # verify if we have a valid buffer_id, if yes avoid to send both
> # flow_mod & packet_out
> if msg.buffer_id != ofproto.OFP_NO_BUFFER:
> self.add_flow(datapath, 1, match, actions, msg.buffer_id)
> return
> else:
> self.add_flow(datapath, 1, match, actions)
> data = None
> if msg.buffer_id == ofproto.OFP_NO_BUFFER:
> data = msg.data
>
> out = parser.OFPPacketOut(datapath=datapath,
> buffer_id=msg.buffer_id,
> in_port=in_port, actions=actions,
> data=data)
> datapath.send_msg(out)
>
> Thanks,
>
> Alan
>
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
>
>
>
> _______________________________________________
> Ryu-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/ryu-devel
>
------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel