#!/bin/nawk -f # # This is an awk script to set up or drop pvc's for BAGNet for a site # that uses a Synoptics LatisCell switch and Synoptics Host Adapter. # # Syntax: synoptics.awk .map # # get .map from: # ftp://matmos.hpl.hp.com//pub/bagnet/PVC.tables/.shar # # Author: Wieland Holfelder (whd@icsi.berkeley.edu) 9/7/94 # BEGIN { # exact path of the pvc command PVC_CMD = "/usr/local/etc/pvc/pvc"; # exact path of the lcell_pvcbatch command PVCBATCH_CMD = "/usr/lnms/bin/lcell_pvcbatch"; # ip address of the host where the cms software is installed (dotted decimal) CMS_HOST_IP = "128.32.201.58"; # port number on the local switch were the OC3 to pac bell is connected PAC_BELL_PORT= 15; # hardware address of the switch SWITCH_ADDR = "000081074DBA:00"; # --------------------------------------------------------------------------------------- # number of BAGNet hosts at this site NB_OF_BAGNET_HOSTS = 4; # --------------------------------------------------------------------------------------- # port number of the first host of this site (set to 0 if not yet conected) BAGNET_PORT[1] = 1; # ip address of the first host of this site BAGNET_IP[1] = "192.6.28.57"; # mac address of the first host of this site BAGNET_MAC[1] = "0A:00:20:1D:CB:17"; # --------------------------------------------------------------------------------------- # port number of the second host of this site (set to 0 if not yet conected) BAGNET_PORT[2] = 2; # ip address of the second host of this site BAGNET_IP[2] = "192.6.28.58"; # mac address of the second host of this site BAGNET_MAC[2] = "0A:00:20:18:20:E4"; # --------------------------------------------------------------------------------------- # port number of the third host of this site (set to 0 if not yet conected) BAGNET_PORT[3] = 3; # ip address of the third host of this site BAGNET_IP[3] = "192.6.28.59"; # mac address of the third host of this site BAGNET_MAC[3] = "0A:00:20:23:6E:43"; # --------------------------------------------------------------------------------------- # port number of the forth host of this site (set to 0 if not yet conected) BAGNET_PORT[4] = 0; # ip address of the third host of this site BAGNET_IP[4] = "192.6.28.56"; # mac address of the third host of this site BAGNET_MAC[4] = ""; # --------------------------------------------------------------------------------------- # YOU NEED NOT CHANGE ANYTHING BELOW THIS LINE !! # --------------------------------------------------------------------------------------- # first 2 bytes of the dummy mac address (e.g. "10:00") # (rest will be generated) DUMMY_MAC_START = "10:00"; # open call bandwith OC_BW = 0.10 # filename for the command to set up the pvcs in the switch # (will be generated) SET_SWITCH = "set-bagnet-switch"; # filename for the command to drop the pvcs in the switch # (will be generated) DROP_SWITCH = "drop-bagnet-switch"; # file holding the cmds to set up the pvcs (used by lcell_pvcbatch command) # (will be generated) SET_SWITCH_CMDS = "set-bagnet-switch.cmds"; # file holding the cmds to set up the pvcs (used by lcell_pvcbatch command) # (will be generated) DROP_SWITCH_CMDS = "drop-bagnet-switch.cmds"; for (i=1; i<=NB_OF_BAGNET_HOSTS; i++) { # filename for the commands to set up the pvcs on the i. host of this site # (will be generated) SET_CMD[i] = sprintf("set-bagnet-host%d",i); # the pvc.batch files for the i. host (used by pvc -f or loaded # automatically at system start when copied as pvc.batch into /opt/SNPXsa_proto) # (will be generated) PVC_BATCH[i] = sprintf("pvc.batch.host%d",i); # filename for the commands to drop the pvcs on the i. host of this site # (will be generated) DROP_CMD[i] = sprintf("drop-bagnet-host%d",i); }; # filename for the commands to try to ping all bagnet hosts # (will be generated) PING = "ping-bagnet" # --------------------------------------------------------------------------------------- # YOU MUST NOT CHANGE ANYTHING BELOW THIS LINE !! # --------------------------------------------------------------------------------------- printf("# File: %s (used by %s)\n",SET_SWITCH_CMDS, PVCBATCH_CMD)>SET_SWITCH_CMDS; printf("#\n")>SET_SWITCH_CMDS; printf("# SYNOPTICS LaticCell ATM Switch PVC table for BAGNet.\n")>SET_SWITCH_CMDS; printf("#\n")>SET_SWITCH_CMDS; printf("# The OC3 to PacBell is on port %d\n", PAC_BELL_PORT)>SET_SWITCH_CMDS; printf("#\n")>SET_SWITCH_CMDS; printf("# File: %s (used by %s)\n",DROP_SWITCH_CMDS, PVCBATCH_CMD)>DROP_SWITCH_CMDS; printf("#\n")>DROP_SWITCH_CMDS; printf("# SYNOPTICS LaticCell ATM Switch PVC table for BAGNet.\n")>DROP_SWITCH_CMDS; printf("#\n")>DROP_SWITCH_CMDS; printf("# The OC3 to PacBell is on port %d\n", PAC_BELL_PORT)>DROP_SWITCH_CMDS; printf("#\n")>DROP_SWITCH_CMDS; for (host=1; host<=NB_OF_BAGNET_HOSTS; host++) { if (BAGNET_PORT[host]!=0) { printf("# Host %12s is connected to switch port %d\n", BAGNET_IP[host], \ BAGNET_PORT[host]) >SET_SWITCH_CMDS; printf("# Host %12s is connected to switch port %d\n", BAGNET_IP[host], \ BAGNET_PORT[host]) >DROP_SWITCH_CMDS; printf("#!/bin/sh\n")>SET_CMD[host]; printf("# Set up PVCs at the SYNOPTICS LatiCell ATM adapter for host %s.\n",\ BAGNET_IP[host])>SET_CMD[host]; printf("# NOTE THAT THIS COMMAND MUST BE STARTED ONLY ON THIS HOST ! \n") \ >SET_CMD[host]; printf("#\n")>SET_CMD[host]; printf("# The switch port of this host is %d \n",BAGNET_PORT[host])>SET_CMD[host]; printf("\n")>SET_CMD[host]; printf("if (test -z \"`ifconfig sa0|awk '{getline;print $2;getline}'|fgrep %s`\")\n", BAGNET_IP[host])>SET_CMD[host]; printf("then\n")>SET_CMD[host]; printf(" echo \"\nThis command must be started on host %s.\n\"\n", \ BAGNET_IP[host])>SET_CMD[host]; printf(" exit 1\n")>SET_CMD[host]; printf("fi\n")>SET_CMD[host]; printf("\n")>SET_CMD[host]; printf("rm -f %s.out\n",SET_CMD[host])>SET_CMD[host]; printf("touch %s.out\n",SET_CMD[host])>SET_CMD[host]; printf("\n")>SET_CMD[host]; printf("#\n")>SET_CMD[host]; printf("# NOTE THAT THE REMOTE MAC ADDRESSES ARE ONLY DUMMY ADDRESSES !\n")\ >SET_CMD[host]; printf("#\n")>SET_CMD[host]; printf("\n")>SET_CMD[host]; printf("#!/bin/sh\n")>DROP_CMD[host]; printf("# Drop PVCs at the SYNOPTICS LatiCell ATM adapter for host %s.\n",\ BAGNET_IP[host])>DROP_CMD[host]; printf("# NOTE THAT THIS COMMAND MUST BE STARTED ONLY ON THIS HOST ! \n") \ >DROP_CMD[host]; printf("#\n")>DROP_CMD[host]; printf("# The switch port of this host is %d \n",BAGNET_PORT[host])>DROP_CMD[host]; printf("\n")>DROP_CMD[host]; printf("if (test -z \"`ifconfig sa0|awk '{getline;print $2;getline}'|fgrep %s`\")\n", BAGNET_IP[host])>DROP_CMD[host]; printf("then\n")>DROP_CMD[host]; printf(" echo \"\nThis command must be started on host %s.\n\"\n", \ BAGNET_IP[host])>DROP_CMD[host]; printf(" exit 1\n")>DROP_CMD[host]; printf("fi\n")>DROP_CMD[host]; printf("\n")>DROP_CMD[host]; printf("rm -f %s.out\n",DROP_CMD[host])>DROP_CMD[host]; printf("touch %s.out\n",DROP_CMD[host])>DROP_CMD[host]; printf("\n")>DROP_CMD[host]; printf("#\n")>DROP_CMD[host]; printf("# NOTE THAT THE REMOTE MAC ADDRESSES ARE ONLY DUMMY ADDRESSES !\n")\ >DROP_CMD[host]; printf("#\n")>DROP_CMD[host]; printf("\n")>DROP_CMD[host]; } else { printf("# Host %12s is not yet connected to bagnet.\n",\ BAGNET_IP[host])>SET_SWITCH_CMDS; printf("# Host %12s is not yet connected to bagnet.\n",\ BAGNET_IP[host])>DROP_SWITCH_CMDS; }; }; printf("#\n")>SET_SWITCH_CMDS; printf("#\n")>DROP_SWITCH_CMDS; } { # DO FOR EACH RECORD: host=0; for (i=1; i<=NB_OF_BAGNET_HOSTS; i++) if ($3==BAGNET_IP[i]) host=i; if (host==0) { # generate dummy mac address for remote sites using DUMMY_MAC_START and # every byte of the destination address as the last for DUMMY_MAC bytes. split($3,x,"."); MAC_ADDR=sprintf("%s:%s:%s:%s:%s",DUMMY_MAC_START,int2hex(x[1]), \ int2hex(x[2]),int2hex(x[3]),int2hex(x[4])); } else { if (BAGNET_PORT[host]==0) next; MAC_ADDR=BAGNET_MAC[host]; }; host=0; for (i=1; i<=NB_OF_BAGNET_HOSTS; i++) if ($1==BAGNET_IP[i]) host=i; if (host>0 && $7=="host") { if (BAGNET_PORT[host]==0) next; for (i=1; i<=NB_OF_HOSTS; i++) if (($3==BAGNET_IP[i]) && (BAGNET_PORT[i]==0)) next; printf("%s -s %14s %17s %3d %3.2f llc >> %s.out 2>&1 \n",PVC_CMD, $3, \ MAC_ADDR, $5, OC_BW, SET_CMD[host]) >SET_CMD[host] ; printf("%14s %17s %3d %3.2f llc\n",$3,MAC_ADDR,$5,OC_BW)>PVC_BATCH[host] ; printf("OC PP VC %s %2d 0 %3d %s %2d 0 %3d %3.2f\n",\ SWITCH_ADDR, BAGNET_PORT[host], $5, SWITCH_ADDR, PAC_BELL_PORT, $10, OC_BW) \ > SET_SWITCH_CMDS; printf("%s -d %14s >> %s.out 2>&1 \n",PVC_CMD, $3, SET_CMD[host])>DROP_CMD[host]; printf("DC -- -- %s %2d 0 %3d %s %2d 0 %3d\n",\ SWITCH_ADDR, BAGNET_PORT[host], $5, SWITCH_ADDR, PAC_BELL_PORT, $10)\ > DROP_SWITCH_CMDS; } } END { for (i=1; i<=NB_OF_BAGNET_HOSTS; i++) { if (BAGNET_PORT[i]!=0) { printf("\n# end\n") > SET_CMD[i]; printf("\n# end\n") > DROP_CMD[i]; }; }; printf ("\n# end\n")>SET_SWITCH_CMDS; printf ("\n# end\n")>DROP_SWITCH_CMDS; printf ("#! /bin/sh\n")>SET_SWITCH; printf ("# Set up SYNOPTICS LaticCell ATM Switch PVCs\n")>SET_SWITCH; printf ("#\n")>SET_SWITCH; printf ("# Make sure that you run this command on a\n")>SET_SWITCH; printf ("# host which has the lnms software installed.\n")>SET_SWITCH; printf ("#\n")>SET_SWITCH; printf ("\n")>SET_SWITCH; printf("rm -f %s.out\n",SET_SWITCH)>SET_SWITCH ; printf("touch %s.out\n",SET_SWITCH)>SET_SWITCH ; printf ("\n")>SET_SWITCH; printf ("sleep 30\n")>SET_SWITCH; printf ("\n")>SET_SWITCH; printf ("%s -b %s -i %s > %s.out 2>&1\n", PVCBATCH_CMD, SET_SWITCH_CMDS,\ CMS_HOST_IP, SET_SWITCH)>SET_SWITCH; printf ("\n# end\n")>SET_SWITCH; printf ("#! /bin/sh\n")>DROP_SWITCH; printf ("# Drop SYNOPTICS LaticCell ATM Switch PVCs\n")>DROP_SWITCH; printf ("#\n")>DROP_SWITCH; printf ("# Make sure that you run this command on a\n")>DROP_SWITCH; printf ("# host which has the lnms software installed.\n")>DROP_SWITCH; printf ("#\n")>DROP_SWITCH; printf ("\n")>DROP_SWITCH; printf("rm -f %s.out\n",DROP_SWITCH)>DROP_SWITCH ; printf ("\n")>DROP_SWITCH; printf ("%s -b %s -i %s > %s.out 2>&1 \n",PVCBATCH_CMD,DROP_SWITCH_CMDS,\ CMS_HOST_IP, DROP_SWITCH)>DROP_SWITCH; printf ("\n# end\n")>DROP_SWITCH; printf("#! /bin/csh -f\n") > PING; printf("set netaddr = 192.6.28 # BAGNET network address\n") > PING; printf("set timeout = 2 # specified in seconds\n") > PING; printf("set i = 1\n") > PING; printf("while ( $i < 255 )\n") > PING; printf(" ping $netaddr.$i $timeout | grep alive\n") > PING; printf(" @ i++\n") > PING; printf("end\n") > PING; printf("#! /bin/csh -f\n") > "clean-up"; printf("#\n") > "clean-up"; printf("# use this file to clean up all files generated by synoptics.awk\n") > "clean-up"; printf("#\n") > "clean-up"; for (i=1; i<=NB_OF_BAGNET_HOSTS; i++) { if (BAGNET_PORT[i]!=0) { printf("rm -f %s\n",SET_CMD[i]) > "clean-up"; printf("rm -f %s\n",DROP_CMD[i]) > "clean-up"; printf("rm -f %s\n",PVC_BATCH[i]) > "clean-up"; printf("rm -f %s.out\n",SET_CMD[i]) > "clean-up"; printf("rm -f %s.out\n",DROP_CMD[i]) > "clean-up"; }; }; printf("rm -f %s\n",PING) > "clean-up"; printf("rm -f %s\n",SET_SWITCH) > "clean-up"; printf("rm -f %s\n",DROP_SWITCH) > "clean-up"; printf("rm -f %s.out\n",SET_SWITCH) > "clean-up"; printf("rm -f %s.out\n",DROP_SWITCH) > "clean-up"; printf("rm -f %s\n",SET_SWITCH_CMDS) > "clean-up"; printf("rm -f %s\n",DROP_SWITCH_CMDS) > "clean-up"; printf("rm -f clean-up\n") > "clean-up"; printf("#end\n") > "clean-up"; for (i=1; i<=NB_OF_BAGNET_HOSTS; i++) { if (BAGNET_PORT[i]!=0) { printf("chmod 700 %s\n",SET_CMD[i]) > "my_chmod.sh"; printf("chmod 700 %s\n",DROP_CMD[i]) > "my_chmod.sh"; }; }; printf("chmod 700 %s\n",PING) > "my_chmod.sh"; printf("chmod 700 %s\n",SET_SWITCH) > "my_chmod.sh"; printf("chmod 700 %s\n",DROP_SWITCH) > "my_chmod.sh"; printf("chmod 700 clean-up\n")> "my_chmod.sh"; printf("rm -f my_chmod.sh\n") > "my_chmod.sh"; printf("#end\n") > "my_chmod.sh"; system("sh my_chmod.sh"); } function int2hex(i) { s=""; j=i; while (j>0) { r=j%16; if(r==10) r="A"; if(r==11) r="B"; if(r==12) r="C"; if(r==13) r="D"; if(r==14) r="E"; if(r==15) r="F"; s=sprintf("%s%s",r,s); j=int(j/16); }; if (length(s)==1) return sprintf("0%s",s); else return s; };