This repository has been archived by the owner on Jun 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 99
How to use match
Arya Seghatoleslami edited this page Jul 10, 2017
·
19 revisions
Built-in fields are:
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 | Requires the ethtype and protocol to be set |
dstport | int | 8080 | |
ethtype | int | 1 | |
protocol | int | 17 | Requires the ethtype to be set |
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, protocol=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"))
Standard boolean logic applies here:
# Anything not in the 10.0.0.0-10.255.255.255 subnet
~match(srcip='10.0.0.0/8')
# Anything in one of these private subnets
match(srcip='10.0.0.0/8') | match(srcip=192.168.0.0/16)
# From localhost to localhost
match(srcip='127.0.0.0/8') & match(dstip='127.0.0.0/8')
# Or:
match(srcip='127.0.0.0/8', dstip='127.0.0.0/8')