Module: Scriptroute::Tulip

Defined in:
lib/scriptroute/tulip/loss.rb,
lib/scriptroute/tulip/helper.rb,
lib/scriptroute/tulip/queuing.rb,
lib/scriptroute/tulip/reordering.rb

Defined Under Namespace

Modules: LangChecker Classes: AliasResolution, LossDoctor, LossTrain, QueueTrain, QueuingDoctor, ReordTrain, ReorderingDoctor, TraceHop, TracePath, Train, Train2

Instance Method Summary collapse

Instance Method Details

#computeFWMedCing(triplets) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/scriptroute/tulip/queuing.rb', line 88

def computeFWMedCing (triplets) 
  #  triplets = Array.new();
  oldsend, oldrcv = 0,0;
  #  stamps.each { |stamp|
  #    triplets.push(stamp);
  #  }
  
  ENV['datalinepattern'] ="newexp";
  ENV['fieldseparator'] = ":";
  ENV['hostfieldnum'] = "3";
  ENV['sentfieldnum'] = "6";
  ENV['receivedfieldnum'] = "7";
  ENV['bouncedfieldnum'] = "9";
  ENV['segmentsecs'] = "12";
  ENV['writefixeddir'] = "./";
  ENV['sourceskew'] = "-";
  ENV['target'] = "1.1.1.1";
  ENV['showquality'] = "1";
  
  pid = Process.pid;
  tmp = File.new("/tmp/fixLC.#{pid}", "w");
  
  if (triplets.length == 0) then
    return -100;
  end
  
  base = triplets[0][0];
  triplets.each_index { |j| 
    tup = triplets[j];
    tmp.puts "0.000:newexp:1.1.1.1:%u:0:%u:%u:0:%u" %[j, tup[0] - base, tup[1], tup[2] - base];
  }
  tmp.close();
  cmd = sprintf("#{FIXCLOCK} /tmp/fixLC.#{pid}");
  output = `#{cmd}`.split("\n");
  match = nil;
  quality = [nil, nil];
  output.each { |o|
    if ( o =~ "inferred stdroundtrip" ) then
      words = o.split;
      quality = [words[4], words[6]];
    end
  }
  
  otts = Array.new();
  rejected = 0;
  tmp = File.new("./fixLC.#{pid}.fix");
  tmp.each { |line| 
    words = line.split(":");
    snd,rem,zero,rcv = words[5..8].map { |i| i.to_i; }
    #    if (snd <= rem and rem <= rcv) then
    otts.push(rem - snd);
    #    else
    #      rejected += 1;
    #    end
  }
  tmp.close();
  File.delete("/tmp/fixLC.#{pid}", "./fixLC.#{pid}.fix", "./fixLC.#{pid}.rej");
  
  #puts "conglib-warning: rejected #{rejected} cing corrections\n" if (rejected > 0);

  otts.sort!;
  #STDERR.puts "WARNING: too few ott samples: #{otts.length}" if (otts.length < 5);
  
  medianDiff = (otts.length > 0)? (otts[otts.length/2] - otts[0]) : -100;
  #puts "otts (#{otts.length}, #{medianDiff}): #{otts.join(" ")}";
  return [[medianDiff, otts.last], quality];
end

#computeRTMed(stamps) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/scriptroute/tulip/queuing.rb', line 74

def computeRTMed (stamps) 
  rtts = Array.new();
  stamps.each { |stamp|
    rtts.push(stamp[2] - stamp[0]);
  }
  rtts.sort!;
  if (rtts.length > 0) 
    medianDiff = rtts[rtts.length/2] - rtts[0];
    return [medianDiff, rtts.first, rtts.last];
  else
    return -100;
  end
end

#convertByteOrder(wrong) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/scriptroute/tulip/queuing.rb', line 43

def convertByteOrder(wrong)
  right = Array.new();
  right[0], right[1], right[2], right[3] =  wrong & 255, 
                                           (wrong & (255 << 8)) >> 8, 
                                           (wrong & (255 << 16)) >> 16, 
                                           (wrong & (255 << 24)) >> 24;
  out = ( (right[0] << 24) + (right[1] << 16) + (right[2] << 8) + right[3]);
  #puts "#{wrong} #{out} #{right.join(" ")}\n";
  return out;
end

#fixByteOrder(stamps) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/scriptroute/tulip/queuing.rb', line 54

def fixByteOrder (stamps) 
  if (stamps.length > 4 and 
      (stamps[0][1] > stamps[1][1] or 
       stamps[1][1] > stamps[2][1] or 
       stamps[2][1] > stamps[3][1] or 
       stamps[3][1] > stamps[4][1] 
       ) 
      ) then
    triplets = Array.new();
    stamps.each_index { |i|
      triplets[i] = Array.new();
      triplets[i][0] = stamps[i][0];
      triplets[i][1] = convertByteOrder(stamps[i][1]);
      triplets[i][2] = stamps[i][2];                 ## a better way to do this would be to insert in converted byte order
    }
    return triplets;
  end
  return stamps;
end