SensorList.cc 11.5 KB
Newer Older
Robert Ricci's avatar
Robert Ricci committed
1 2
/*
 * Copyright (c) 2006 University of Utah and the Flux Group.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 * 
 * {{{EMULAB-LICENSE
 * 
 * This file is part of the Emulab network testbed software.
 * 
 * This file is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or (at
 * your option) any later version.
 * 
 * This file is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
 * License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this file.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * }}}
Robert Ricci's avatar
Robert Ricci committed
22 23
 */

24 25 26
// SensorList.cc

#include "lib.h"
27
#include "log.h"
28
#include "SensorList.h"
29 30
#include "Sensor.h"
#include "Command.h"
31

32
#include "StateSensor.h"
33 34 35 36 37
#include "PacketSensor.h"
#include "DelaySensor.h"
#include "MinDelaySensor.h"
#include "MaxDelaySensor.h"
#include "ThroughputSensor.h"
38
#include "TSThroughputSensor.h"
39
#include "EwmaThroughputSensor.h"
40
#include "LeastSquaresThroughput.h"
41

42 43 44 45
using namespace std;

SensorList::SensorList()
{
46
  reset();
47 48 49 50
}

SensorList::SensorList(SensorList const & right)
{
51 52 53 54 55 56 57
  if (right.head.get() != NULL)
  {
    logWrite(ERROR, "SensorList copy constructed after setup. "
             "This shouldn't have been able to happen. "
             "Sensors have been lost.");
  }
  reset();
58 59 60 61
}

SensorList & SensorList::operator=(SensorList const & right)
{
62 63 64
  if (this != &right)
  {
    if (right.head.get() != NULL)
65
    {
66 67 68
      logWrite(ERROR, "SensorList assigned after setup. "
               "This shouldn't have been able to happen. "
               "Sensors have been lost.");
69
    }
70
    reset();
71 72
  }
  return *this;
73 74 75 76
}

void SensorList::addSensor(SensorCommand const & newSensor)
{
77 78 79
  // Add dependency type demux here.
  switch(newSensor.type)
  {
80
  case NULL_SENSOR:
81 82
    pushNullSensor();
    break;
83 84 85
  case STATE_SENSOR:
    pushStateSensor();
    break;
86 87 88 89 90 91 92 93 94 95 96 97 98 99
  case PACKET_SENSOR:
    pushPacketSensor();
    break;
  case DELAY_SENSOR:
    pushDelaySensor();
    break;
  case MIN_DELAY_SENSOR:
    pushMinDelaySensor();
    break;
  case MAX_DELAY_SENSOR:
    pushMaxDelaySensor();
    break;
  case THROUGHPUT_SENSOR:
    pushThroughputSensor();
100
    break;
101 102 103
  case TSTHROUGHPUT_SENSOR:
    pushTSThroughputSensor();
    break;
104 105 106
  case EWMA_THROUGHPUT_SENSOR:
    pushEwmaThroughputSensor();
    break;
107 108 109
  case LEAST_SQUARES_THROUGHPUT:
    pushLeastSquaresThroughput();
    break;
110 111 112
  case AVERAGE_THROUGHPUT_SENSOR:
    pushAverageThroughputSensor();
    break;
113 114 115 116 117 118 119 120 121 122 123 124
  case UDP_PACKET_SENSOR:
    pushUdpPacketSensor();
    break;
  case UDP_THROUGHPUT_SENSOR:
    pushUdpThroughputSensor();
    break;
  case UDP_MINDELAY_SENSOR:
    pushUdpMinDelaySensor();
    break;
  case UDP_MAXDELAY_SENSOR:
    pushUdpMaxDelaySensor();
    break;
125 126 127 128 129 130 131 132 133
  case UDP_RTT_SENSOR:
    pushUdpRttSensor();
    break;
  case UDP_LOSS_SENSOR:
    pushUdpLossSensor();
    break;
  case UDP_AVG_THROUGHPUT_SENSOR:
    pushUdpAvgThroughputSensor();
    break;
134 135 136 137 138 139
  default:
    logWrite(ERROR,
             "Incorrect sensor type (%d). Ignoring add sensor command.",
             newSensor.type);
    break;
  }
140 141 142 143
}

Sensor * SensorList::getHead(void)
{
144
  return head.get();
145 146
}

147
void SensorList::reset(void)
148 149 150 151 152
{
  head.reset(NULL);
  tail = NULL;
  // Dependency = NULL here
  depNullSensor = NULL;
153
  depStateSensor = NULL;
154 155 156
  depPacketSensor = NULL;
  depDelaySensor = NULL;
  depThroughputSensor = NULL;
157
  depTSThroughputSensor = NULL;
158
  depMinDelaySensor = NULL;
159 160 161 162 163 164 165 166 167 168 169

  depUdpPacketSensor = NULL;
  depUdpThroughputSensor = NULL;
  depUdpMinDelaySensor = NULL;
  depUdpMaxDelaySensor = NULL;
  depUdpRttSensor = NULL;
  depUdpLossSensor = NULL;
  depUdpAvgThroughputSensor = NULL;



170 171
}

172

173
void SensorList::pushSensor(std::auto_ptr<Sensor> newSensor)
174
{
175 176 177
  if (tail != NULL)
  {
    tail->addNode(newSensor);
178
    tail = tail->getTail();
179 180 181 182 183 184
  }
  else
  {
    head = newSensor;
    tail = head.get();
  }
185 186 187 188
}

// Add individual pushSensor functions here.

189
void SensorList::pushNullSensor(void)
190 191 192 193 194 195
{
  // Dependency list

  // Example dependency check
  if (depNullSensor == NULL)
  {
196
    logWrite(SENSOR, "Adding NullSensor");
197 198 199 200 201 202 203 204
    NullSensor * newSensor = new NullSensor();
    std::auto_ptr<Sensor> current(newSensor);
    pushSensor(current);

    // Example dependency set
    depNullSensor = newSensor;
  }
}
205

206 207 208
void SensorList::pushStateSensor(void)
{
  // Dependency list
209
  pushNullSensor();
210 211 212 213 214 215 216 217 218 219 220 221 222 223

  // Dependency check
  if (depStateSensor == NULL)
  {
    logWrite(SENSOR, "Adding StateSensor");
    StateSensor * newSensor = new StateSensor();
    std::auto_ptr<Sensor> current(newSensor);
    pushSensor(current);

    // Dependency set
    depStateSensor = newSensor;
  }
}

224 225 226
void SensorList::pushPacketSensor(void)
{
  // Dependency list
227
  pushStateSensor();
228 229 230 231

  // Example dependency check
  if (depPacketSensor == NULL)
  {
232 233
    logWrite(SENSOR, "Adding PacketSensor");
    PacketSensor * newSensor = new PacketSensor(depStateSensor);
234 235 236 237 238 239 240 241 242 243 244
    std::auto_ptr<Sensor> current(newSensor);
    pushSensor(current);

    // Example dependency set
    depPacketSensor = newSensor;
  }
}

void SensorList::pushDelaySensor(void)
{
  // Dependency list
245
  pushStateSensor();
246 247 248 249 250
  pushPacketSensor();

  // Example dependency check
  if (depDelaySensor == NULL)
  {
251 252
    logWrite(SENSOR, "Adding DelaySensor");
    DelaySensor * newSensor = new DelaySensor(depPacketSensor, depStateSensor);
253 254 255 256 257 258 259 260 261 262 263 264 265
    std::auto_ptr<Sensor> current(newSensor);
    pushSensor(current);

    // Example dependency set
    depDelaySensor = newSensor;
  }
}

void SensorList::pushMinDelaySensor(void)
{
  // Dependency list
  pushDelaySensor();

266 267 268 269 270 271 272 273 274
  if (depMinDelaySensor == NULL) {
      logWrite(SENSOR, "Adding MinDelaySensor");
      MinDelaySensor * newSensor = new MinDelaySensor(depDelaySensor);
      std::auto_ptr<Sensor> current(newSensor);
      pushSensor(current);

      // Dependency set
      depMinDelaySensor = newSensor;
  }
275

276 277 278 279 280
}

void SensorList::pushMaxDelaySensor(void)
{
  // Dependency list
281
  pushMinDelaySensor();
282
  pushDelaySensor();
283
  pushStateSensor();
284
  pushPacketSensor();
285

286
  logWrite(SENSOR, "Adding MaxDelaySensor");
287
  std::auto_ptr<Sensor> current(new MaxDelaySensor(depDelaySensor,
288
                                                   depStateSensor,
289 290
                                                   depMinDelaySensor,
                                                   depPacketSensor));
291 292 293 294 295 296
  pushSensor(current);
}

void SensorList::pushThroughputSensor(void)
{
  // Dependency list
297
  pushStateSensor();
298 299 300 301 302
  pushPacketSensor();

  // Example dependency check
  if (depThroughputSensor == NULL)
  {
303 304 305
    logWrite(SENSOR, "Adding ThroughputSensor");
    ThroughputSensor * newSensor = new ThroughputSensor(depPacketSensor,
                                                        depStateSensor);
306 307 308 309 310 311 312
    std::auto_ptr<Sensor> current(newSensor);
    pushSensor(current);

    // Example dependency set
    depThroughputSensor = newSensor;
  }
}
313

314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
void SensorList::pushTSThroughputSensor(void)
{
  // Dependency list
  pushStateSensor();
  pushPacketSensor();

  // Example dependency check
  if (depTSThroughputSensor == NULL)
  {
    logWrite(SENSOR, "Adding TSThroughputSensor");
    TSThroughputSensor * newSensor = new TSThroughputSensor(depPacketSensor,
                                                            depStateSensor);
    std::auto_ptr<Sensor> current(newSensor);
    pushSensor(current);

    // Example dependency set
    depTSThroughputSensor = newSensor;
  }
}

334 335 336
void SensorList::pushEwmaThroughputSensor(void)
{
  // Dependency list
337
  pushStateSensor();
338 339 340
  pushThroughputSensor();

  logWrite(SENSOR, "Adding EwmaThroughputSensor");
341 342
  std::auto_ptr<Sensor> current(new EwmaThroughputSensor(depThroughputSensor,
                                                         depStateSensor));
343 344
  pushSensor(current);
}
345 346 347 348

void SensorList::pushLeastSquaresThroughput(void)
{
  // Dependency list
349
  pushTSThroughputSensor();
350 351 352
  pushDelaySensor();

  logWrite(SENSOR, "Adding LeastSquaresThroughput");
353
  std::auto_ptr<Sensor> current(new LeastSquaresThroughput(depTSThroughputSensor,
354 355 356
                                                           depDelaySensor));
  pushSensor(current);
}
357 358 359 360 361

void SensorList::pushAverageThroughputSensor(void)
{
  // Dependency list
  pushTSThroughputSensor();
362
  pushDelaySensor();
363 364

  logWrite(SENSOR, "Adding AverageThroughputSensor");
365 366 367
  std::auto_ptr<Sensor> current(
    new LeastSquaresThroughput(depTSThroughputSensor, depDelaySensor,
                               LeastSquaresThroughput::DEFAULT_MAX_PERIOD));
368 369
  pushSensor(current);
}
370 371 372

void SensorList::pushUdpPacketSensor()
{
373 374
  pushNullSensor();

375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428
  // Example dependency check
  if (depUdpPacketSensor == NULL)
  {
    logWrite(SENSOR, "Adding UdpPacketSensor");
    UdpPacketSensor * newSensor = new UdpPacketSensor();

    std::auto_ptr<Sensor> current(newSensor);
    pushSensor(current);

    // Example dependency set
    depUdpPacketSensor = newSensor;
  }

}
void SensorList::pushUdpThroughputSensor()
{
  pushUdpPacketSensor();

  // Example dependency check
  if (depUdpThroughputSensor == NULL)
  {
    logWrite(SENSOR, "Adding UdpThroughputSensor");
    UdpThroughputSensor * newSensor = new UdpThroughputSensor(depUdpPacketSensor);

    std::auto_ptr<Sensor> current(newSensor);
    pushSensor(current);

    // Example dependency set
    depUdpThroughputSensor = newSensor;
  }

}
void SensorList::pushUdpMinDelaySensor()
{
  pushUdpPacketSensor();

  // Example dependency check
  if (depUdpMinDelaySensor == NULL)
  {
    logWrite(SENSOR, "Adding UdpMinDelaySensor");
    UdpMinDelaySensor * newSensor = new UdpMinDelaySensor(depUdpPacketSensor);

    std::auto_ptr<Sensor> current(newSensor);
    pushSensor(current);

    // Example dependency set
    depUdpMinDelaySensor = newSensor;
  }

}
void SensorList::pushUdpMaxDelaySensor()
{
  pushUdpPacketSensor();
  pushUdpMinDelaySensor();
429
  pushUdpLossSensor();
430 431 432 433 434

  // Example dependency check
  if (depUdpMaxDelaySensor == NULL)
  {
    logWrite(SENSOR, "Adding UdpMaxDelaySensor");
435
    UdpMaxDelaySensor * newSensor = new UdpMaxDelaySensor(depUdpPacketSensor, depUdpMinDelaySensor, depUdpLossSensor);
436 437 438 439 440 441 442 443 444

    std::auto_ptr<Sensor> current(newSensor);
    pushSensor(current);

    // Example dependency set
    depUdpMaxDelaySensor = newSensor;
  }

}
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503

void SensorList::pushUdpRttSensor()
{
  pushUdpPacketSensor();

  // Example dependency check
  if (depUdpRttSensor == NULL)
  {
    logWrite(SENSOR, "Adding UdpRttSensor");
    UdpRttSensor * newSensor = new UdpRttSensor(depUdpPacketSensor);

    std::auto_ptr<Sensor> current(newSensor);
    pushSensor(current);

    // Example dependency set
    depUdpRttSensor = newSensor;
  }

}

void SensorList::pushUdpLossSensor()
{
  pushUdpPacketSensor();
  pushUdpRttSensor();

  // Example dependency check
  if (depUdpLossSensor == NULL)
  {
    logWrite(SENSOR, "Adding UdpLossSensor");
    UdpLossSensor * newSensor = new UdpLossSensor(depUdpPacketSensor, depUdpRttSensor);

    std::auto_ptr<Sensor> current(newSensor);
    pushSensor(current);

    // Example dependency set
    depUdpLossSensor = newSensor;
  }

}

void SensorList::pushUdpAvgThroughputSensor()
{
  pushUdpPacketSensor();
  pushUdpLossSensor();

  // Example dependency check
  if (depUdpAvgThroughputSensor == NULL)
  {
    logWrite(SENSOR, "Adding UdpAvgThroughputSensor");
    UdpAvgThroughputSensor * newSensor = new UdpAvgThroughputSensor(depUdpPacketSensor, depUdpLossSensor);

    std::auto_ptr<Sensor> current(newSensor);
    pushSensor(current);

    // Example dependency set
    depUdpAvgThroughputSensor = newSensor;
  }

}