wss.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 1991-1994 Regents of the University of California.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. All advertising materials mentioning features or use of this software
00014  *    must display the following acknowledgement:
00015  *  This product includes software developed by the University of
00016  *  California, Berkeley and the Network Research Group at
00017  *  Lawrence Berkeley Laboratory.
00018  * 4. Neither the name of the University nor of the Laboratory may be used
00019  *    to endorse or promote products derived from this software without
00020  *    specific prior written permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00023  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00024  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00025  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00026  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00027  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00028  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00029  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00031  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00032  * SUCH DAMAGE.
00033  *
00034  */
00035 
00036 
00037 /* it is used to generate the Weight Spread Sequence of SRR 
00038  * WSS and SRR are named by Dr. W. Qi 
00039  */
00040 
00041 /*
00042 #include <stdio.h>
00043 #include <math.h>
00044 #include <string.h>
00045 #include <stdlib.h>
00046 */
00047 
00048 class PacketSRR;
00049 class SRR;
00050 
00051 int power( int base, int j)
00052 {
00053     int r=1; int i;
00054     if(j==0) return 1;
00055     else
00056     {
00057         for(i=0;i<j;i++)
00058         r*=base;
00059     }
00060 
00061     return r;
00062 }
00063 
00064 void rawScan( int i, int j, int N, int *p)
00065 {
00066     if(j==N)
00067     {
00068         *p=N;
00069         return;
00070     }
00071 
00072     if(i%(int)power(2,j))
00073     {
00074         *p=j;
00075         return;
00076     }
00077     else
00078         rawScan(i, j+1, N, p);
00079 }
00080 
00081 class WSS{
00082     public:WSS(): currOrder(1), items(0), ptr(0), pwss(0){ }
00083     friend class SRR;
00084 public: 
00085     int maxOrder; // the order of the WSS
00086     int currOrder; // current order of WSS
00087     int items; //how many items are in the WSS
00088     unsigned int ptr;
00089     int *pwss;  // 
00090     void init(int i);
00091 
00092     int get_ptr()
00093     {
00094       return ptr;
00095     }
00096 
00097     void set_ptr (int val){
00098         ptr = val;
00099     }
00100 
00101     void inc_ptr ( int order)
00102     {
00103         ptr += 1;
00104         if((int)ptr > ((1<<order)-2))
00105         {
00106             ptr = 0;
00107         }
00108     }
00109 
00110     int get(int order);
00111 
00112     void print(); // for debug purpose
00113 
00114 };
00115 
00116 void WSS::init(int i){
00117     int j;
00118     maxOrder=i;
00119     items= (1<<maxOrder)-1;
00120     ptr=0;
00121     pwss=(int*)malloc(sizeof(int)*items);
00122     
00123     for(j=1;j<=items; j++)
00124         rawScan(j, 1, maxOrder,  (int*)(pwss+j-1));
00125 }
00126 
00127 int WSS::get(int order)  // it should also tells the WSS the order
00128 {  
00129     int value;
00130 
00131     currOrder=order;
00132 
00133     //printf("get wss\n");
00134     int tmp = 1 << order;
00135     if((int)ptr > (tmp-2))
00136     {
00137         printf("tmp :%d \n", tmp);
00138         printf("error, too large ptr:%d, order:%d\n", (int)ptr, order);
00139         exit(0);
00140     }
00141 
00142     value= *(pwss+ptr);
00143     return value;
00144 }
00145 
00146 void WSS::print(){
00147     int i;
00148     for(i=0;i<items;i++)
00149         printf("%4d", *(pwss+i));
00150     printf("\n");
00151 }
00152 
00153 /*
00154 main(int argc,  char **argv)
00155 {
00156     WSS wss;
00157     if(argc!=2)
00158     {
00159         printf("usage:%s number\n", argv[0]);
00160         exit(0);
00161     }
00162     wss.init(atoi(argv[1]));
00163     wss.print();
00164 }
00165 */

Generated on Tue Mar 6 16:47:53 2007 for ns2 Network Simulator 2.29 by  doxygen 1.4.6