Commit cfb2c159 authored by Julien Muchembled's avatar Julien Muchembled

demo: duplicate code from Nemu for future monkey-patching

parent 16f87a30
......@@ -38,6 +38,8 @@ def _add_interface(node, iface):
return Node__add_interface(node, iface)
nemu.Node._add_interface = _add_interface
# create nodes
for name in """internet=I registry=R
gateway1=g1 machine1=1 machine2=2
# -*- coding: utf-8 -*-
# Copyright 2010, 2011 INRIA
# Copyright 2011 Martín Ferrari <>
# This file is contains patches to Nemu.
# Nemu is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License version 2, as published by the Free
# Software Foundation.
# Nemu is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along with
# Nemu. If not, see <>.
import re
from nemu.iproute import backticks, get_if_data, get_all_route_data, route
def _get_all_route_data():
ipdata = backticks([IP_PATH, "-o", "route", "list"]) # "table", "all"
ipdata += backticks([IP_PATH, "-o", "-f", "inet6", "route", "list"])
ifdata = get_if_data()[1]
ret = []
for line in ipdata.split("\n"):
if line == "":
match = re.match(r'(?:(unicast|local|broadcast|multicast|throw|' +
r'unreachable|prohibit|blackhole|nat) )?' +
r'(\S+)(?: via (\S+))? dev (\S+).*(?: metric (\d+))?', line)
if not match:
raise RuntimeError("Invalid output from `ip route': `%s'" % line)
tipe = or "unicast"
prefix =
nexthop =
interface = ifdata[]
metric =
if prefix == "default" or'/0$', prefix):
prefix = None
prefix_len = 0
match = re.match(r'([0-9a-f:.]+)(?:/(\d+))?$', prefix)
prefix =
prefix_len = int( or 32)
ret.append(route(tipe, prefix, prefix_len, nexthop, interface.index,
return ret
get_all_route_data.func_code = _get_all_route_data.func_code
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment