|
| 1 | +################################################################################ |
| 2 | +# The Pyretic Project # |
| 3 | +# frenetic-lang.org/pyretic # |
| 4 | +# author: Joshua Reich ([email protected]) # |
| 5 | +################################################################################ |
| 6 | +# Licensed to the Pyretic Project by one or more contributors. See the # |
| 7 | +# NOTICES file distributed with this work for additional information # |
| 8 | +# regarding copyright and ownership. The Pyretic Project licenses this # |
| 9 | +# file to you under the following license. # |
| 10 | +# # |
| 11 | +# Redistribution and use in source and binary forms, with or without # |
| 12 | +# modification, are permitted provided the following conditions are met: # |
| 13 | +# - Redistributions of source code must retain the above copyright # |
| 14 | +# notice, this list of conditions and the following disclaimer. # |
| 15 | +# - Redistributions in binary form must reproduce the above copyright # |
| 16 | +# notice, this list of conditions and the following disclaimer in # |
| 17 | +# the documentation or other materials provided with the distribution. # |
| 18 | +# - The names of the copyright holds and contributors may not be used to # |
| 19 | +# endorse or promote products derived from this work without specific # |
| 20 | +# prior written permission. # |
| 21 | +# # |
| 22 | +# Unless required by applicable law or agreed to in writing, software # |
| 23 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # |
| 24 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # |
| 25 | +# LICENSE file distributed with this work for specific language governing # |
| 26 | +# permissions and limitations under the License. # |
| 27 | +################################################################################ |
| 28 | + |
| 29 | +################################################################################ |
| 30 | +# SETUP # |
| 31 | +# ------------------------------------------------------------------- # |
| 32 | +# mininet: mininet.sh --topo=single,3,3 (or other single subnet network) # |
| 33 | +# test: h1 python2 -m SimpleHTTPServer 3000 # |
| 34 | +# h2 curl 10.0.0.1:3000 # |
| 35 | +# # |
| 36 | +# It should output: # |
| 37 | +# # |
| 38 | +################################################################################ |
| 39 | + |
| 40 | +from pyretic.lib.corelib import * |
| 41 | +from pyretic.lib.std import * |
| 42 | +from pyretic.lib.query import * |
| 43 | +from pyretic.modules.mac_learner import mac_learner |
| 44 | + |
| 45 | +def print_urls(pkt, match): |
| 46 | + print 'verb: %-5s | path: %-25s | version: %-3s' % match.groups() |
| 47 | + |
| 48 | +### Main ### |
| 49 | +def main(): |
| 50 | + re = RegexpQuery("(?P<verb>GET|POST|DELETE|PUT|HEAD)\s*(?P<path>.*?)\s*HTTP/(?P<http>.*?)\n") |
| 51 | + re.register_callback(print_urls) |
| 52 | + |
| 53 | + return mac_learner() + re |
0 commit comments