Skip to content
This repository was archived by the owner on Jun 27, 2018. It is now read-only.

How to use match

Rick van Hattem edited this page Jul 12, 2015 · 19 revisions

match(f=v): match packets whose field f has value v

Built-in fields are:

Requires the ethtype and protocol to be set
FIELD TYPE EXAMPLE NOTES
switch int 4
inport int 3
outport int 2
srcmac EthAddr EthAddr('00:00:00:00:00:01')
dstmac EthAddr EthAddr('00:00:00:00:00:03')
srcip IPAddr or string IPAddr('10.0.1.1'), '10.0.0.0/24'
dstip IPAddr or string IPAddr('10.0.1.2'), '10.0.0.1/24'
tos int 0
srcport int 80
dstport int 8080
ethtype int 1
protocol int 7
vlan_id int 0
vlan_pcp int 0

Examples:

from pyretic.core import packet
match(srcip=IPAddr("1.1.1.2"))
match(srcip="1.1.1.0/24"))
match(srcmac=EthAddr("00:00:00:00:00:01"))   
match(switch=4)
match(dstport=8080, ethtype=packet.IPV4, protocl=packet.TCP_PROTO)

match also supports multiple field value pairs seperated by a comma - e.g.,

match(switch=4, srcmac=MAC("00:00:00:00:00:01"))

which means exactly the same thing as

match(switch=4) & match(srcmac=MAC("00:00:00:00:00:01"))
Clone this wiki locally