<s> '''<STR_LIT>''' <EOL> from vnode import * <EOL> from vnet import * <EOL> from core . constants import * <EOL> from core . misc . ipaddr import * <EOL> from core . api import coreapi <EOL> from core . bsd . netgraph import ngloadkernelmodule <EOL> checkexec ( [ IFCONFIG_BIN ] ) <EOL> class CoreNode ( JailNode ) : <EOL> apitype = coreapi . CORE_NODE_DEF <EOL> class PtpNet ( NetgraphPipeNet ) : <EOL> def tonodemsg ( self , flags ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> def tolinkmsgs ( self , flags ) : <EOL> '''<STR_LIT>''' <EOL> tlvdata = "<STR_LIT>" <EOL> if len ( self . _netif ) != <NUM_LIT:2> : <EOL> return tlvdata <EOL> ( if1 , if2 ) = self . _netif . items ( ) <EOL> if1 = if1 [ <NUM_LIT:1> ] <EOL> if2 = if2 [ <NUM_LIT:1> ] <EOL> tlvdata += coreapi . CoreLinkTlv . pack ( coreapi . CORE_TLV_LINK_N1NUMBER , <EOL> if1 . node . objid ) <EOL> tlvdata += coreapi . CoreLinkTlv . pack ( coreapi . CORE_TLV_LINK_N2NUMBER , <EOL> if2 . node . objid ) <EOL> delay = if1 . getparam ( '<STR_LIT>' ) <EOL> bw = if1 . getparam ( '<STR_LIT>' ) <EOL> loss = if1 . getparam ( '<STR_LIT>' ) <EOL> duplicate = if1 . getparam ( '<STR_LIT>' ) <EOL> jitter = if1 . getparam ( '<STR_LIT>' ) <EOL> if delay is not None : <EOL> tlvdata += coreapi . CoreLinkTlv . pack ( coreapi . CORE_TLV_LINK_DELAY , <EOL> delay ) <EOL> if bw is not None : <EOL> tlvdata += coreapi . CoreLinkTlv . pack ( coreapi . CORE_TLV_LINK_BW , bw ) <EOL> if loss is not None : <EOL> tlvdata += coreapi . CoreLinkTlv . pack ( coreapi . CORE_TLV_LINK_PER , <EOL> str ( loss ) ) <EOL> if duplicate is not None : <EOL> tlvdata += coreapi . CoreLinkTlv . pack ( coreapi . CORE_TLV_LINK_DUP , <EOL> str ( duplicate ) ) <EOL> if jitter is not None : <EOL> tlvdata += coreapi . CoreLinkTlv . pack ( coreapi . CORE_TLV_LINK_JITTER , <EOL> jitter ) <EOL> tlvdata += coreapi . CoreLinkTlv . pack ( coreapi . CORE_TLV_LINK_TYPE , <EOL> self . linktype ) <EOL> tlvdata += coreapi . CoreLinkTlv . pack ( coreapi . CORE_TLV_LINK_IF1NUM , if1 . node . getifindex ( if1 ) ) <EOL> if if1 . hwaddr : <EOL> tlvdata += coreapi . CoreLinkTlv . pack ( coreapi . CORE_TLV_LINK_IF1MAC , <EOL> if1 . hwaddr ) <EOL> for addr in if1 . addrlist : <EOL> ( ip , sep , mask ) = addr . partition ( '<STR_LIT:/>' ) <EOL> mask = int ( mask ) <EOL> if isIPv4Address ( ip ) : <EOL> family = AF_INET <EOL> tlvtypeip = coreapi . CORE_TLV_LINK_IF1IP4 <EOL> tlvtypemask = coreapi . CORE_TLV_LINK_IF1IP4MASK <EOL> else : <EOL> family = AF_INET6 <EOL> tlvtypeip = coreapi . CORE_TLV_LINK_IF1IP6 <EOL> tlvtypemask = coreapi . CORE_TLV_LINK_IF1IP6MASK <EOL> ipl = socket . inet_pton ( family , ip ) <EOL> tlvdata += coreapi . CoreLinkTlv . pack ( tlvtypeip , <EOL> IPAddr ( af = family , addr = ipl ) ) <EOL> tlvdata += coreapi . CoreLinkTlv . pack ( tlvtypemask , mask ) <EOL> tlvdata += coreapi . CoreLinkTlv . pack ( coreapi . CORE_TLV_LINK_IF2NUM , if2 . node . getifindex ( if2 ) ) <EOL> if if2 . hwaddr : <EOL> tlvdata += coreapi . CoreLinkTlv . pack ( coreapi . CORE_TLV_LINK_IF2MAC , <EOL> if2 . hwaddr ) <EOL> for addr in if2 . addrlist : <EOL> ( ip , sep , mask ) = addr . partition ( '<STR_LIT:/>' ) <EOL> mask = int ( mask ) <EOL> if isIPv4Address ( ip ) : <EOL> family = AF_INET <EOL> tlvtypeip = coreapi . CORE_TLV_LINK_IF2IP4 <EOL> tlvtypemask = coreapi . CORE_TLV_LINK_IF2IP4MASK <EOL> else : <EOL> family = AF_INET6 <EOL> tlvtypeip = coreapi . CORE_TLV_LINK_IF2IP6 <EOL> tlvtypemask = coreapi . CORE_TLV_LINK_IF2IP6MASK <EOL> ipl = socket . inet_pton ( family , ip ) <EOL> tlvdata += coreapi . CoreLinkTlv . pack ( tlvtypeip , <EOL> IPAddr ( af = family , addr = ipl ) ) <EOL> tlvdata += coreapi . CoreLinkTlv . pack ( tlvtypemask , mask ) <EOL> msg = coreapi . CoreLinkMessage . pack ( flags , tlvdata ) <EOL> return [ msg , ] <EOL> class SwitchNode ( NetgraphNet ) : <EOL> ngtype = "<STR_LIT>" <EOL> nghooks = "<STR_LIT>" <EOL> apitype = coreapi . CORE_NODE_SWITCH <EOL> policy = "<STR_LIT>" <EOL> class HubNode ( NetgraphNet ) : <EOL> ngtype = "<STR_LIT>" <EOL> nghooks = "<STR_LIT>" <EOL> apitype = coreapi . CORE_NODE_HUB <EOL> policy = "<STR_LIT>" <EOL> class WlanNode ( NetgraphNet ) : <EOL> ngtype = "<STR_LIT>" <EOL> nghooks = "<STR_LIT>" <EOL> apitype = coreapi . CORE_NODE_WLAN <EOL> linktype = coreapi . CORE_LINK_WIRELESS <EOL> policy = "<STR_LIT>" <EOL> def __init__ ( self , session , objid = None , name = None , verbose = False , <EOL> start = True , policy = None ) : <EOL> NetgraphNet . __init__ ( self , session , objid , name , verbose , start , policy ) <EOL> self . model = None <EOL> self . mobility = None <EOL> def attach ( self , netif ) : <EOL> NetgraphNet . attach ( self , netif ) <EOL> if self . model : <EOL> netif . poshook = self . model . _positioncallback <EOL> if netif . node is None : <EOL> return <EOL> ( x , y , z ) = netif . node . position . get ( ) <EOL> netif . poshook ( netif , x , y , z ) <EOL> def setmodel ( self , model , config ) : <EOL> '''<STR_LIT>''' <EOL> if ( self . verbose ) : <EOL> self . info ( "<STR_LIT>" % model . _name ) <EOL> if model . _type == coreapi . CORE_TLV_REG_WIRELESS : <EOL> self . model = model ( session = self . session , objid = self . objid , <EOL> verbose = self . verbose , values = config ) <EOL> if self . model . _positioncallback : <EOL> for netif in self . netifs ( ) : <EOL> netif . poshook = self . model . _positioncallback <EOL> if netif . node is not None : <EOL> ( x , y , z ) = netif . node . position . get ( ) <EOL> netif . poshook ( netif , x , y , z ) <EOL> self . model . setlinkparams ( ) <EOL> elif model . _type == coreapi . CORE_TLV_REG_MOBILITY : <EOL> self . mobility = model ( session = self . session , objid = self . objid , <EOL> verbose = self . verbose , values = config ) <EOL> class RJ45Node ( NetgraphPipeNet ) : <EOL> apitype = coreapi . CORE_NODE_RJ45 <EOL> policy = "<STR_LIT>" <EOL> def __init__ ( self , session , objid , name , verbose , start = True ) : <EOL> if start : <EOL> ngloadkernelmodule ( "<STR_LIT>" ) <EOL> NetgraphPipeNet . __init__ ( self , session , objid , name , verbose , start ) <EOL> if start : <EOL> self . setpromisc ( True ) <EOL> def shutdown ( self ) : <EOL> self . setpromisc ( False ) <EOL> NetgraphPipeNet . shutdown ( self ) <EOL> def setpromisc ( self , promisc ) : <EOL> p = "<STR_LIT>" <EOL> if not promisc : <EOL> p = "<STR_LIT:->" + p <EOL> check_call ( [ IFCONFIG_BIN , self . name , "<STR_LIT>" , p ] ) <EOL> def attach ( self , netif ) : <EOL> if len ( self . _netif ) > <NUM_LIT:0> : <EOL> raise ValueError , "<STR_LIT>" <EOL> NetgraphPipeNet . attach ( self , netif ) <EOL> connectngnodes ( self . ngname , self . name , self . gethook ( ) , "<STR_LIT>" ) <EOL> class TunnelNode ( NetgraphNet ) : <EOL> ngtype = "<STR_LIT>" <EOL> nghooks = "<STR_LIT>" <EOL> apitype = coreapi . CORE_NODE_TUNNEL <EOL> policy = "<STR_LIT>" </s>
