[Click] random bit errors element

Alastair McKinley amckinley03 at qub.ac.uk
Thu Feb 23 09:12:27 EST 2006


Hi everyone,

I would like to use the RandomBitErrors element to produce a lower bit
error rate than currently possible.  At the moment its minimum bit error
rate is 2x10-5.  So I've been trying to figure out how this element
works and unfortunately in my lameness, I haven't quite got to the
bottom of it.  I want to use 28 bits of fraction for the conversion of
the bit error configuration string.

I've made a guess at how it might work and attached a diff.  Would
someone be able to tell me if this will work correctly? 

Best regards and thanks,

Alastair




--- randomerror.cc.bak	2006-02-23 12:08:51.000000000 +0000
+++ randomerror.cc	2006-02-23 13:54:23.000000000 +0000
@@ -83,9 +83,9 @@
 void
 RandomBitErrors::set_bit_error(unsigned bit_error)
 {
-  assert(bit_error <= 0x10000);
+  assert(bit_error <= 0x10000000);
   _p_bit_error = bit_error;
-  unsigned non_bit_error = (0xFFFF - bit_error) + 1;
+  unsigned non_bit_error = (0xFFFFFFF - bit_error) + 1;
   // _p_error[i] is the probability that i bits are flipped.
   // _p_error[i] = bit_error^i * (1-bit_error)^(8-i) * #combinations
   
@@ -93,13 +93,13 @@
   for (int i = 0; i < 9; i++) {
     uint64_t p = 0x100000000LL;
     for (int j = 0; j < i; j++)
-      p = (p * bit_error) >> 16;
+      p = (p * bit_error) >> 28;
     for (int j = i; j < 8; j++)
-      p = (p * non_bit_error) >> 16;
+      p = (p * non_bit_error) >> 28;
     // account for # of combinations
     p *= bit_flip_array_idx[i+1] - bit_flip_array_idx[i];
     accum += p;
-    _p_error[i] = (accum >> 16) & 0x1FFFF;
+    _p_error[i] = (accum >> 28) & 0x1FFFFFFF;
     if ((accum & 0xFFFFFFFF) >= 0x80000000)
       _p_error[i]++;
   }
@@ -112,7 +112,7 @@
   String kind_str = "flip";
   bool on = true;
   if (cp_va_parse(conf, this, errh,
-		  cpUnsignedReal2, "bit error probability", 16, &bit_error,
+		  cpUnsignedReal2, "bit error probability", 28, &bit_error,
 		  cpOptional,
 		  cpString, "action (set/clear/flip)", &kind_str,
 		  cpBool, "active?", &on,
@@ -130,7 +130,7 @@
     return errh->error("bad action '%s' (must be 'set', 'clear', or 'flip')",
 		       kind_str.c_str());
   
-  if (bit_error > 0x10000)
+  if (bit_error > 0x10000000)
     return errh->error("drop probability must be between 0 and 1");
   if (bit_error == 0)
     errh->warning("zero bit error probability (underflow?)");
@@ -147,7 +147,7 @@
 RandomBitErrors::simple_action(Packet *p_in)
 {
   // if no chance we'll flip a bit, return now
-  if (!_on || _p_error[0] >= 0x10000)
+  if (!_on || _p_error[0] >= 0x10000000)
     return p_in;
   
   WritablePacket *p = p_in->uniqueify();
@@ -184,7 +184,7 @@
   int which = (intptr_t)vwhich;
   RandomBitErrors *lossage = (RandomBitErrors *)f;
   if (which == 0)
-    return cp_unparse_real2(lossage->p_bit_error(), 16);
+    return cp_unparse_real2(lossage->p_bit_error(), 28);
   else if (which == 1) {
     switch (lossage->kind()) {
      case 0: return "clear";








More information about the click mailing list