#!/usr/local/bin/python # Takes as input the IP of a cuda CMTS and # builds a cricket configuration file named # "interfaces". Assumes cable interfaces are 1x6; # also handles Fast and Gig ethernet interfaces. # Will probably require customization for, for # example, the cricket target-type. # #author: K.C. Smith, kace@cox.com import sys, os ip = sys.argv[1] if ip == '' : raise StandardError, 'usage: buildcudaconf ' comm = 'putsnmpcommstringhere' sltd = {} cabledescr = 'CATV MAC: Broadcom BCM3210' etherdescr = 'fbus:' posdescr = 'SONET/SDH Medium/Section/Line' # ifMIB.ifMIBObjects.ifXTable.ifXEntry.ifHighSpeed inslot = os.popen('snmpwalk '+ip+' '+comm+' enterprises.3493.2.2.1.2.1.2') rawslot = inslot.readline().split() while rawslot != [] : inst = int(rawslot[0][rawslot[0].rfind('.')+1:]) # special code for 8 way FastE cards if sltd.has_key(rawslot[2]) : sltd[rawslot[2]+'_'+repr(inst-sltd[rawslot[2]]+1)] = inst if inst-sltd[rawslot[2]] == 7 : del sltd[rawslot[2]] sltd[rawslot[2]+'_1'] = inst-7 rawslot = inslot.readline().split() continue # end special code sltd[rawslot[2]] = inst rawslot = inslot.readline().split() inslot.close() clist = [] elist = [] plist = [] ulist = [] slots = sltd.keys() def sbv(a,b) : if sltd[a] > sltd[b] : return 1 elif sltd[a] < sltd[b] : return -1 else : return 0 slots.sort(sbv) for sl in slots : inst = repr(sltd[sl]) rawdescr = os.popen('snmpget '+ip+' '+comm+' interfaces.ifTable.ifEntry.ifDescr.'+inst+' interfaces.ifTable.ifEntry.ifAdminStatus.'+inst+' interfaces.ifTable.ifEntry.ifSpeed.'+inst ) descr = rawdescr.readline() descr = descr[descr.rfind('=')+2:-1] astat = rawdescr.readline() astat = astat[astat.rfind('=')+2:-1] if descr[:26] == cabledescr : if astat == 'up(1)' : clist.append(sl) elif descr[:5] == etherdescr : if astat == 'up(1)' : elist.append(sl) speed = rawdescr.readline() speed = speed[speed.rfind('=')+2:-1] if speed == 'Gauge32: 1000000000' : elist[-1] = [ elist[-1] , 'GigabitEthernet'+sl ] elif speed == 'Gauge32: 100000000' : elist[-1] = [ elist[-1] , 'FastEthernet'+sl ] else : elist[-1] = [ elist[-1] , 'UnknownEthernet'+sl ] elif descr[:29] == posdescr : if astat == 'up(1)' : plist.append(sl) else : ulist.append(sl) rawdescr.close() for unk in ulist : print "unknown descr for slot : ", print unk outfile = open('interfaces','w') outfile.write('target --default--\n router = '+ip+'\n\n') nameplus = [['','norminterface'], ['-downstream','cabledownstream'], ['-upstream1','cableupstream'], ['-upstream2','cableupstream'], ['-upstream3','cableupstream'], ['-upstream4','cableupstream'], ['-upstream5','cableupstream'], ['-upstream6','cableupstream'] ] for slot in clist : for plus in nameplus : outfile.write('target Cable'+slot+'_1'+plus[0]+'\n target-type = '+plus[1]+'\n inst = '+repr(sltd[slot]+nameplus.index(plus))+'\n short-desc = "Cable'+slot+'/1'+plus[0]+'"\n\n') for slot in elist : if not slot[1].find('_')+1 : slot[1] = slot[1]+'_1' if slot[1][:4] == 'Giga' : itype = 'basicinterface' rmax = '125000000' elif slot[1][:4] == 'Fast' : itype = 'norminterface' rmax = '12500000' # debug code else : print slot print elist break outfile.write('target '+slot[1]+'\n target-type = '+itype+'\n inst = '+repr(sltd[slot[0]])+'\n short-desc = "'+slot[1].replace('_','/')+'"\n rrd-max = '+rmax+'\n\n') for slot in plist : outfile.write('target POS'+slot+'_1\n target-type = norminterface\n inst = '+repr(sltd[slot])+'\n short-desc = "POS'+slot+'/1"\n\n')