def ip4route_test_goodstr_goodplen_impliedmetric(): rt = ip4route.IP4Route("192.168.1.1", 24) assert_equals(rt.isValid(), True) assert_equals(rt.getMetric(), 0) assert_equals(rt.getAddr()[0], "192.168.1.1") assert_equals(rt.getPlen(), 24)
def ip4route_test_goodstr_goodplen_goodmetric(): rt = ip4route.IP4Route("192.168.1.1", 24, 0) assert_equals(rt.isValid(), True) assert_equals(rt.getMetric(), 0) assert_equals(rt.getAddr(), ("192.168.1.1", 3232235777)) assert_equals(rt.getMask(), ("255.255.255.0", 4294967040)) assert_equals(rt.getHostmask(), ("0.0.0.255", 255)) assert_equals(rt.getBroadcast(), ("192.168.1.255", 3232236031)) assert_equals(rt.getNetwork(), ("192.168.1.0", 3232235776)) assert_equals(rt.getPlen(), 24)
def main(argv): rtlist = [] for rtstr in argv[1:]: ret = rtstr.split("/") if (ret.__len__() != 2): print("Error, use CIDR notation (e.g. 1.1.1.1/24):", rtstr) return 255 try: addr, mask = ret[0], int(ret[1]) except: print("Error, use CIDR notation (e.g. 1.1.1.1/24):", rtstr) return 255 rt = ip4route.IP4Route(addr, mask) if (rt.isValid() == False): print("Error, invalid route:", rtstr) return 255 rtlist.append(rt) if (rtlist == []): print("One or more valid routes required.") return 255 rtlist, summarized = acrs.summarize(rtlist) for rt in rtlist: assert(rt.isValid() == True) print(rt) if summarized == True: return 0 elif summarized == False: return 1 else: assert(False)
def ip4route_test_goodstr_badplen_goodmetric(): rt = ip4route.IP4Route("192.168.1.1", -1, 0) assert_equals(rt.isValid(), False) assert_equals(rt.getMetric(), None)
def ip4route_test_goodstr_goodplen_badmetric_negative(): rt = ip4route.IP4Route("192.168.1.1", 24, -1) assert_equals(rt.isValid(), False) assert_equals(rt.getMetric(), None)
def ip4route_test_set_metric_good(): rt = ip4route.IP4Route("192.168.1.1", 24, 1) assert_equals(rt.isValid(), True) rt.setMetric(2) assert_equals(rt.getMetric(), 2)
def ip4route_test_set_plen_good(): rt = ip4route.IP4Route("192.168.1.1", 24) assert_equals(rt.isValid(), True) rt.setPlen(23) assert_equals(rt.getPlen(), 23)
def ip4route_test_goodstr_goodplen_badmetric_toohigh(): rt = ip4route.IP4Route("192.168.1.1", 24, 65536) assert_equals(rt.isValid(), False) assert_equals(rt.getMetric(), None)
def main(): rtlist = [] print "Content-type: text/html\n\n" print "<h1>Results:</h1>" print "(Use your browser's back button to return to the previous page.)" print "</br></br>" # If an exception is thrown, cgitb will allow errors to be printed to # the web page, in addition to the python version and a timestamp. # This is useful for debugging purposes. If you don't want this to happen, # either comment out the next line, or see the python documentation # on how to make it write to a log file. cgitb.enable() form = cgi.FieldStorage() if (not "summary-input" in form): print "Error: One or more prefixes required." return 1 args = form["summary-input"].value.split() if (args.__len__() > ARGS_LIMIT): print "The web version of this demo is artificially limited to", \ ARGS_LIMIT, "prefixes so the web server doesn't get too bogged " \ "down. Consider downloading a command line version from " \ "acrs.googlecode.com (it's open source and no cost) " \ "or bribing the server operator to increase ARGS_LIMIT in ", \ "acrs-web-demo.py." return 1 for rtstr in args: ret = rtstr.split("/") if (ret.__len__() != 2): print "Error, use CIDR notation (e.g. 1.1.1.0/24):", rtstr return 1 try: addr, mask = ret[0], int(ret[1]) except: print "Error, use CIDR notation (e.g. 1.1.1.0/24):", rtstr return 1 rt = ip4route.IP4Route(addr, mask) if (rt.isValid() == False): print "Error, invalid route:", rtstr return 1 rtlist.append(rt) if (rtlist == []): print "One or more valid routes required." return 1 rtlist, summarized = acrs.summarize(rtlist) for rt in rtlist: assert (rt.isValid() == True) print rt, "</br>" return 0