コード例 #1
0
    def subnetentry(x):
        ''' Generate a subnet declaration block given an IPv4 prefix string
            for inclusion in the config file.
	'''
        if x.find(":") >= 0:
            # this is an IPv6 address
            return ''
        else:
            net = IPv4Prefix(x)
            return 'ip rule add from %s table 224 pref 80' % (net)
コード例 #2
0
 def subnetentry2(x):
     ''' Generate a subnet declaration block given an IPv4 prefix string
         for inclusion in the config file.
     '''
     if x.find(":") >= 0:
         # this is an IPv6 address
         return ""
     else:
         net = IPv4Prefix(x)
         return '\tlan   %s domain=0\n' % (net)
コード例 #3
0
ファイル: buster_server.py プロジェクト: wkyoun/atn-sim-ng-1
 def subnetentry(x):
     ''' Generate a subnet declaration block given an IPv4 prefix string
         for inclusion in the config file.
     '''
     if x.find(":") >= 0:
         # this is an IPv6 address
         return ""
     else:
         net = IPv4Prefix(x)
         return 'echo "  network %s"' % (net)
コード例 #4
0
 def generatequaggaconfig(cls, node):
     cfg = "router ospf\n"
     rtrid = cls.routerid(node)
     cfg += "  router-id %s\n" % rtrid
     # network 10.0.0.0/24 area 0
     for ifc in node.netifs():
         if hasattr(ifc, 'control') and ifc.control == True:
             continue
         for a in ifc.addrlist:
             if a.find(".") < 0:
                 continue
             net = IPv4Prefix(a)
             cfg += "  network %s area 0\n" % net
     cfg += "!\n"
     return cfg
コード例 #5
0
ファイル: nrl.py プロジェクト: zhangshunkang/coreemu
 def firstipv4prefix(node, prefixlen=24):
     ''' Similar to QuaggaService.routerid(). Helper to return the first IPv4
     prefix of a node, using the supplied prefix length. This ignores the
     interface's prefix length, so e.g. '/32' can turn into '/24'.
     '''
     for ifc in node.netifs():
         if hasattr(ifc, 'control') and ifc.control == True:
             continue
         for a in ifc.addrlist:
             if a.find(".") >= 0:
                 addr = a.split('/')[0]
                 pre = IPv4Prefix("%s/%s" % (addr, prefixlen))
                 return str(pre)
     #raise ValueError,  "no IPv4 address found"
     return "0.0.0.0/%s" % prefixlen
コード例 #6
0
 def addrstr(x):
     if x.find(":") >= 0:
         net = IPv6Prefix(x)
         fam = "inet6 ::"
     else:
         net = IPv4Prefix(x)
         fam = "inet 0.0.0.0"
     if net.maxaddr() == net.minaddr():
         return ""
     else:
         if os.uname()[0] == "Linux":
             rtcmd = "ip route add default via"
         elif os.uname()[0] == "FreeBSD":
             rtcmd = "route add -%s" % fam
         else:
             raise Exception, "unknown platform"
         return "%s %s" % (rtcmd, net.minaddr())
コード例 #7
0
 def routestr(x):
     if x.find(":") >= 0:
         net = IPv6Prefix(x)
         fam = "inet6"
         dst = "3ffe:4::/64"
     else:
         net = IPv4Prefix(x)
         fam = "inet"
         dst = "10.9.8.0/24"
     if net.maxaddr() == net.minaddr():
         return ""
     else:
         if os.uname()[0] == "Linux":
             rtcmd = "#/sbin/ip route add %s via" % dst
         elif os.uname()[0] == "FreeBSD":
             rtcmd = "#/sbin/route add -%s %s" % (fam, dst)
         else:
             raise Exception, "unknown platform"
         return "%s %s" % (rtcmd, net.minaddr())
コード例 #8
0
    def subnetentry(x):
        ''' Generate a subnet declaration block given an IPv4 prefix string
            for inclusion in the dhcpd3 config file.
        '''
        if x.find(":") >= 0:
            return ""
        else:
            addr = x.split("/")[0]
            net = IPv4Prefix(x)
            # divide the address space in half
            rangelow = net.addr(net.numaddr() / 2)
            rangehigh = net.maxaddr()
            return """
subnet %s netmask %s {
  pool {
    range %s %s;
    default-lease-time 600;
    option routers %s;
  }
}
""" % (net.prefixstr(), net.netmaskstr(), rangelow, rangehigh, addr)