#! /usr/bin/perl # # use XML::XPath; use XML::XPath::Node::Comment; my $burl='&wl;'; my $xp = XML::XPath->new(ioref => *DATA); my ($root) = $xp->findnodes('/'); my ($exodus) = $xp->findnodes('//Exodus'); my ($Locations) = $xp->findnodes('//Locations'); my ($Services) = $xp->findnodes('//Services'); my ($Nodes) = $xp->findnodes('//Nodes'); my ($AntennaTypes) = $xp->findnodes('//AntennaTypes'); my ($Hardwarez) = $xp->findnodes('//Hardwarez'); my ($Links) = $xp->findnodes('//Links'); my ($Measurements) = $xp->findnodes('//Measurements'); my ($Softwarez) = $xp->findnodes('//Softwarez'); if ($#ARGV eq -1) {die "Usage: genesis2xml node*/wleiden.conf\n";} foreach $file (@ARGV) { print "Working on: $file\n"; local($node)=@_; local($r,$if,$main,$wireless)=''; local($X,$Y,$Real_X,$RealY); local(%config,%DESC,%SDESC,%ANTENNA,%BEAMWIDTH,%CABLE,%CHANNEL,%DHCP,%DHCP_STATIC); local(%DIRECTION,%ESSID,%GAIN,%IP,%MODE,%NAT,%OSPF_AREA,%OSPF_BROADCAST); local(%OSPF_NEIGHBORS,%POINT_TO_POINT,%POLAR,%ROUTE,%SENS,%SPEED,%TXPOWER,%TYPE); local($labelpos,$neighbors,$link_file,$int_file); local(%ptp_done); do($file) || die "Could not parse filename: $file\n"; parse_config(); process_config(); } #print $root->toString; print $exodus->toString; print "\n"; open (GENESIS,">genesis.xml") || die "Could not create genesis.xml"; print GENESIS $root->toString; close(GENESIS); sub process_config { $loc_burl="${burl}/Location"; $locationname=$nodename; $locationname=~s/[0-9]$//gi; my ($Location) = $xp->findnodes("//$locationname"); if (! $Location) { $Location=childattrib($Locations,'Location','about',"$loc_burl/" . lc($locationname)); child($Location,'Name',$locationname); child($Location,'Beheerder',"${burl}Beheer/wleiden"); childattrib($Location,'gpos','ref','ETS89',"$X,$Y"); my $slot=childattrib($Location,'slot','about',1,''); child($slot,'Title','None'); my $address=child($Location,'Address'); child($address,'comment',$location); # child($location'ospfAREA',99); } $LocCounter{$locationname}++; $HWCounter++; $id="$locationname$LocCounter{$locationname}"; my $Service=childattrib($Services,'Service','type','wlnode'); attrib($Service,'about',"$burl/Service/$id"); attrib($Service,'location',"$loc_burl/" . lc($locationname)); childattrib($Service,'slot','id',"$loc_burl/" . lc($locationname) . "/Slot/$LocCounter{$locationname}"); my $Node=childattrib($Nodes,'Node','about',"$burl/Node/$nodename"); attrib($Node,'status','InUse'); attrib($Node,'hardware',"$burl/Hardware/$HWCounter"); my $service=childattrib($Node,'service','id',"$loc_burl/" . lc($locationname) . "/Slot/$LocCounter{$locationname}"); $accounter=0;$ifcounter=0; foreach $if (keys %config) { $LinkCounter++; if ($if=~/^([^:]+):(\d+)/) {$mymain=$1;$mysub=$2;} if ($if!~/:\d+/) { $main=1;$ifcounter++;$mymain=$if; $AntennaCounter++; } else {$main=0;} my $link=childattrib($service,'link','id',"$burl/Link/$LinkCounter"); attrib($link,'status','InUse'); attrib($link,'acc','InUse'); if ($DHCP{$if}) {attrib($link,'dhcp',$DHCP{$if});} if ($OSPF_COST{$if}) {attrib($link,'ospfcost',$OSPF_COST{$if});} if ($main) { $AntennaCounter++; my $acc=childattrib($Node,'acc','about',$acccounter); my $antenna=childattrib($Node,'Antenna','about',"$burl/Antenna/$AntennaCounter"); if ($TYPE{$if}=~/wireless/) { attrib($acc,'Antenna',"$burl/Antenna/$AntennaCounter"); attrib($acc,'fixedchannel',"$CHANNEL{$if}"); if ($POLAR{$if}=~/H/) {$polar='Horizontal';} elsif ($POLAR{$if}=~/V/) {$polar='Vertical';} else {$polar='';} if ($polar) {attrib($antenna,'polarisation',$polar);} if ($DIRECTION{$if}) {attrib($antenna,'direction',$DIRECTION{$if});} attrib($antenna,'status','opererational'); if ($ANTENNA{$if}) {attrib($antenna,'type',$ANTENNA{$if});} else { #Hier moet nog iets slims } my $Link=childattrib($Links,'Link','about',$LinkCounter); if ($MODE{$if}=~/master/i) {childattrib($Link,'Master','id',"$burl/Node/$nodename");} elsif ($MODE{$if}=~/slave|managed/i) { $essid=lc($ESSID{$if});$essid=~s/^[^.]+\.([^.]+)\.wleiden.net$/$1/i; $essid=~s/\d+$//gi; childattrib($Link,'Slave','id',"$burl/Node/$essid"); } } attrib($acc,'Interface',"$burl/Hardware/$HWCounter/$ifcounter"); if ($DESC{$if}) {attrib($acc,'description',"$DESC{$if}");} if ($SDESC{$if}) {attrib($acc,'shortdescription',"$SDESC{$if}");} if ($CHANNEL{$if}) {attrib($acc,'fixedchannel',"$CHANNEL{$if}");} attrib($acc,'debug',$if); } my $Link=childattrib($Links,'Link','about',$LinkCounter); $acccounter++; } childattrib($Hardwarez,'Hardware','about',"$burl/Hardware/$HWCounter"); } sub childattrib { local($xml,$childname,$name,$value,$text)=@_; local($child)=child($xml,$childname,$text); attrib($child,$name,$value); return($child); } sub child { local($xml,$childname,$text)=@_; local($child)=XML::XPath::Node::Element->new($childname); if ($text) { local($Text) = XML::XPath::Node::Text->new($text); $child->appendChild($Text); } $xml->appendChild($child); return($child); } sub attrib { local($xml,$name,$value)=@_; local($attribute)=XML::XPath::Node::Attribute->new($name,$value); $xml->appendAttribute($attribute); return($attribute); } sub parse_config { foreach $if (keys %config) { $cfg=$config{$if}; #if (! $html) {print "Parsing interface: $if\n";} while ($cfg) { $cfg=~s/^([^\n\r]+)[\r\n]*//m; $line=$1; $line=~s/\s*#.*//; if ((($name,$value)=split(/=/,$line)) eq 2) { if ($name eq 'ESSID') {$value=lc($value);} #print "VAL($name)=$value\n"; $doit="if (exists(\$$name\{\"$if\"\})) {\$$name\{\"$if\"\}.=\"$separator$value\";} else {\$$name\{\"$if\"\}.=\"$value\";}"; #print "DOIT: [$doit]\n"; eval($doit); } #print "CFG:[$cfg]\n"; $cfg=~s/[\r\n]*$//m; } } if ($functions_only<1) {print "Done parsing config.\n";} } __DATA__ ]> Stichting Wireless Leiden http://www.wleiden.net/" 0 8 SD15 15 25,15 V H 4040 PatchPanel 40 40,40 V H Omni 5 360,80 5 H