1 #!/usr/bin/python 2 3 import dlpi 4 import sys 5 import time 6 import struct 7 8 #test listlink 9 linklist = dlpi.listlink() 10 print "Found %d links:" % len(linklist) 11 print linklist 12 13 #pick up the first data link for below testing 14 linkname = linklist[0] 15 16 #open link 17 print "opening link: " + linkname + "..." 18 testlink = dlpi.link(linkname) 19 20 #read some info of testlink 21 print "linkname is %s" % testlink.get_linkname() 22 print "link fd is %d" % testlink.get_fd() 23 mactype = testlink.get_mactype() 24 print "dlpi mactype is %d" % mactype 25 print "after convert:" 26 print "\tmactype is %s" % dlpi.mactype(mactype) 27 print "\tiftype is %d" % dlpi.iftype(mactype) 28 print "\tarptype is %d" % dlpi.arptype(mactype) 29 bcastaddr = testlink.get_bcastaddr() 30 print "broadcast addr is: ", 31 print struct.unpack("BBBBBB",bcastaddr) 32 physaddr = testlink.get_physaddr(dlpi.FACT_PHYS_ADDR) 33 print "factory physical address is: ", 34 print struct.unpack("BBBBBB",physaddr) 35 print "current timeout value is %d" % testlink.get_timeout() 36 print "sdu is:", 37 print testlink.get_sdu() 38 print "qos select is:", 39 print testlink.get_qos_select() 40 print "qos range is:", 41 print testlink.get_qos_range() 42 43 #set some config value of testlink and read them again 44 print "setting current physiacal addr to aa:0:10:13:27:5" 45 testlink.set_physaddr('\xaa\0\x10\x13\x27\5') 46 physaddr = testlink.get_physaddr(dlpi.CURR_PHYS_ADDR) 47 print "current physical addr is: ", 48 print struct.unpack("BBBBBB",physaddr) 49 print "set timeout value to 6..." 50 testlink.set_timeout(6) 51 print "timeout value is %d" % testlink.get_timeout() 52 53 #test enable/disable multicast 54 print "enable/disable multicast address 1:0:5e:0:0:5" 55 testlink.enabmulti('\1\0\x5e\0\0\5') 56 testlink.disabmulti('\1\0\x5e\0\0\5') 57 58 #test bind 59 print "binding to SAP 0x9000..." 60 testlink.bind(0x9000) 61 print "sap is %x" % testlink.get_sap() 62 print "state is: %d" % testlink.get_state() 63 64 #test send 65 print "sending broadcast loopback packet..." 66 testlink.send(bcastaddr, '\0\1\2\3\4\5') 67 68 #test notify functionality 69 arg = "notification callback arg" 70 def notify(arg, notes, value): 71 print "NOTE_PROMISC_ON_PHYS notification received with arg: '%s'" % arg 72 print "enabled notification on NOTE_PROMISC_ON_PHYS" 73 id = testlink.enabnotify(dlpi.NOTE_PROMISC_ON_PHYS, notify, arg) #enable notification 74 testlink.promiscon() #trigger the event (will be seen while receiving pkt below) 75 76 #test receive 77 print "testing receiving..." 78 try: 79 testlink.recv(0, 0) #should see NOTE_PROMISC_ON_PHYS event here 80 except dlpi.error, err: 81 errnum, errinfo = err 82 if errnum == 10006: 83 pass #timeout error is expected here 84 else: #test fails if reach here 85 print "test failed", 86 print errnum, 87 print err 88 89 testlink.promiscoff() 90 testlink.disabnotify(id) #disable notification 91 92 #test unbind 93 print "unbinding..." 94 testlink.unbind() 95 print "sap is %x" % testlink.get_sap() 96 print "state is: %d" % testlink.get_state() 97