1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 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 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 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 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 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 504 505 506 507 508
|
/*
* Copyright (c) 2001 University of Southern California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the Information Sciences
* Institute of the University of Southern California.
* 4. Neither the name of the University nor of the Institute may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
#include <stdlib.h>
#include <math.h>
#ifdef WIN32
#include <windows.h>
#endif
#include "netview.h"
#include "node.h"
#include "edge.h"
#include "paint.h"
#include "sincos.h"
#include "queuehandle.h"
#define PROPERTY_STRING_LENGTH 256
static int g_queuehandle_number = 1;
//----------------------------------------------------------------------
// Wrapper for creating QueueHandles in OTcl
//----------------------------------------------------------------------
static class QueueHandleClass : public TclClass {
public:
QueueHandleClass() : TclClass("QueueHandle") {}
TclObject* create(int argc, const char * const * argv) {
const char * type;
int id;
double size;
type = argv[4];
id = strtol(argv[5], NULL, 10);
size = strtod(argv[6], NULL);
return (new QueueHandle(type, id, size));
}
} class_queuehandle;
//----------------------------------------------------------------------
//----------------------------------------------------------------------
QueueHandle::QueueHandle(const char* type, int id, double _size) :
Animation(0, 0) {
setDefaults();
number_ = id;
if (g_queuehandle_number++ <= id) {
g_queuehandle_number = id + 1;
}
width_ = 50.0;
height_ = size_/2.0;
size_ = _size;
size(_size);
}
//----------------------------------------------------------------------
//----------------------------------------------------------------------
QueueHandle::QueueHandle(Edge * edge) :
Animation(0, 0) {
Node * node;
setDefaults();
edge_ = edge;
number_ = g_queuehandle_number;
g_queuehandle_number++;
node = edge_->getSourceNode();
if (node) {
size(node->size());
} else {
size(10.0);
}
limit_ = 20;
// FQ
secsPerByte_ = 0.0;
// Stocastic Fair Queue
maxqueue_ = 40;
buckets_ = 16;
// DRR
blimit_ = 2500;
quantum_ = 250;
mask_ = false;
// RED
bytes_ = false;
queue_in_bytes_ = false;
thresh_ = 5.0;
maxthresh_ = 15.0;
mean_pktsize_ = 500;
q_weight_ = 0.002;
wait_ = false;
linterm_ = 30.0;
setbit_ = false;
drop_tail_ = false;
}
//----------------------------------------------------------------------
//----------------------------------------------------------------------
void
QueueHandle::setDefaults() {
next_queue_handle_ = NULL;
edge_ = NULL;
x_ = 0.0;
y_ = 0.0;
angle_ = NO_ANGLE;
if (color_) {
delete []color_;
}
color_ = strdup("black");
paint_ = Paint::instance()->thin();
width_ = 10.0;
height_ = 10.0;
type_ = NULL;
ns_type_ = NULL;
setType("DropTail");
}
//----------------------------------------------------------------------
// double
// QueueHandle::distance(double x, double y) const {
//----------------------------------------------------------------------
double
QueueHandle::distance(double x, double y) const {
return sqrt((x_-x)*(x_-x) + (y_-y)*(y_-y));
}
//----------------------------------------------------------------------
//----------------------------------------------------------------------
void
QueueHandle::color(const char * name) {
if (color_) {
delete []color_;
}
color_ = new char[strlen(name) + 1];
strcpy(color_, name);
}
//----------------------------------------------------------------------
//----------------------------------------------------------------------
void QueueHandle::size(double s) {
size_ = s;
width_ = 10.0 + 25.0;
height_ = s/2.0;
update_bb();
}
//----------------------------------------------------------------------
//----------------------------------------------------------------------
void QueueHandle::update_bb() {
bb_.xmin = x_;
bb_.ymin = y_;
bb_.xmax = x_ + width_;
bb_.ymax = y_ + height_;
}
//----------------------------------------------------------------------
//----------------------------------------------------------------------
void QueueHandle::setType(const char* type) {
const char * expanded_type;
// Expand Ns Type Names
if (!strcmp(type, "FQ")) {
expanded_type = "FairQueue";
} else if (!strcmp(type, "SFQ")) {
expanded_type = "StocasticFairQueue";
} else if (!strcmp(type, "DRR")) {
expanded_type = "DeficitRoundRobin";
} else {
expanded_type = type;
}
// Deleted existing type strings
if (type_) {
delete[] type_;
}
if (ns_type_) {
delete[] ns_type_;
ns_type_ = NULL;
}
// Set type and ns type to new strings
type_ = new char[strlen(expanded_type) + 1];
strcpy(type_, expanded_type);
if (!strcmp(expanded_type, "DropTail")) {
ns_type_ = new char[strlen("DropTail") + 1];
strcpy(ns_type_, "DropTail");
} else if (!strcmp(expanded_type, "FairQueue")) {
ns_type_ = new char[strlen("FQ") + 1];
strcpy(ns_type_, "FQ");
} else if (!strcmp(expanded_type, "StocasticFairQueue")) {
ns_type_ = new char[strlen("SFQ") + 1];
strcpy(ns_type_, "SFQ");
} else if (!strcmp(expanded_type, "DeficitRoundRobin")) {
ns_type_ = new char[strlen("DRR") + 1];
strcpy(ns_type_, "DRR");
} else if (!strcmp(expanded_type, "RED")) {
ns_type_ = new char[strlen("RED") + 1];
strcpy(ns_type_, "RED");
}
}
//----------------------------------------------------------------------
//----------------------------------------------------------------------
void QueueHandle::reset(double) {
paint_ = Paint::instance()->thick();
}
//----------------------------------------------------------------------
// void
// QueueHandle::attach(Agent * agent)
//----------------------------------------------------------------------
void
QueueHandle::attachTo(Edge * edge) {
edge_ = edge;
place();
}
//----------------------------------------------------------------------
//----------------------------------------------------------------------
void QueueHandle::clearEdge() {
edge_ = NULL;
}
//----------------------------------------------------------------------
// void
// QueueHandle::place()
//----------------------------------------------------------------------
void
QueueHandle::place() {
double sine, cosine, angle;
if (edge_) {
angle = edge_->angle();
sine = sin(angle);
cosine = cos(angle);
if ((angle > 0.0 && angle < M_PI/2.0) ||
(angle < M_PI/-2.0 && angle > -1.0*M_PI)) {
x_ = edge_->x() + cosine * height_;
y_ = edge_->y() + sine * height_ - height_;
} else {
x_ = edge_->x() + cosine * height_;
y_ = edge_->y() + sine * height_;
}
}
update_bb();
}
//----------------------------------------------------------------------
//----------------------------------------------------------------------
const char* QueueHandle::info() const {
static char text[128];
sprintf(text, "Queue Type: %s %d->%d", type_, edge_->src(), edge_->dst());
return (text);
}
//----------------------------------------------------------------------
// int
// QueueHandle::inside(double, float px, float py) const
// - Check to see if point (px, py) is within the Loss Model box
//----------------------------------------------------------------------
int
QueueHandle::inside(double, float px, float py) const {
return (px >= x_ &&
px <= (x_ + width_) &&
py >= y_ &&
py <= (y_ + height_));
}
//----------------------------------------------------------------------
// void
// QueueHandle::draw(View * view, double ) const
// - Draw the Loss Model on its edge
//----------------------------------------------------------------------
void
QueueHandle::draw(View * view, double time) {
double label_width, label_height, label_x, label_y;
const char * label = "Q";
if (edge_) {
// Draw label centered inside of border
// We have to keep calculting the label width and height because
// we have no way of knowing if the user has zoomed in or out
// on the current network view.
label_height = 0.9 * height_;
label_width = view->getStringWidth(label, label_height);
// Add 10% of padding to width for the box
setWidth(1.1 * label_width);
// Center label in box
label_x = x_ + (width_ - label_width);
label_y = y_ + (height_ - label_height);
view->string(label, label_x , label_y, label_height, NULL);
update_bb();
// Draw Rectangle Border
view->rect(x_, y_, x_ + width_, y_ + height_ , paint_);
}
}
//----------------------------------------------------------------------
// int
// QueueHandle::writeNsScript(FILE * file)
// - outputs ns script format for creating loss models
//----------------------------------------------------------------------
int
QueueHandle::writeNsScript(FILE * file) {
if (edge_) {
fprintf(file, "# Set Queue Properties for link %d->%d\n", edge_->src(), edge_->dst());
if (!strcmp(type_, "DropTail")) {
fprintf(file, "[[$ns link $node(%d) $node(%d)] queue] set limit_ %d\n", edge_->src(), edge_->dst(), limit_);
} else if (!strcmp(type_, "FairQueue")) {
fprintf(file, "[[$ns link $node(%d) $node(%d)] queue] set secsPerByte_ %f\n", edge_->src(), edge_->dst(), secsPerByte_);
} else if (!strcmp(type_, "StocasticFairQueue")) {
fprintf(file, "[[$ns link $node(%d) $node(%d)] queue] set maxqueue_ %d\n", edge_->src(), edge_->dst(), maxqueue_);
fprintf(file, "[[$ns link $node(%d) $node(%d)] queue] set buckets_ %d\n", edge_->src(), edge_->dst(), buckets_);
} else if (!strcmp(type_, "DeficitRoundRobin")) {
fprintf(file, "[[$ns link $node(%d) $node(%d)] queue] set buckets_ %d\n", edge_->src(), edge_->dst(), buckets_);
fprintf(file, "[[$ns link $node(%d) $node(%d)] queue] set blimit_ %d\n", edge_->src(), edge_->dst(), blimit_);
fprintf(file, "[[$ns link $node(%d) $node(%d)] queue] set quantum_ %d\n", edge_->src(), edge_->dst(), quantum_);
if (mask_) {
fprintf(file, "[[$ns link $node(%d) $node(%d)] queue] set mask_ 1\n", edge_->src(), edge_->dst());
}
} else if (!strcmp(type_, "RED")) {
if (bytes_) {
fprintf(file, "[[$ns link $node(%d) $node(%d)] queue] set bytes_ 1\n", edge_->src(), edge_->dst());
}
if (queue_in_bytes_) {
fprintf(file, "[[$ns link $node(%d) $node(%d)] queue] set queue_in_bytes_ 1\n", edge_->src(), edge_->dst());
}
fprintf(file, "[[$ns link $node(%d) $node(%d)] queue] set thresh_ %f\n", edge_->src(), edge_->dst(), thresh_);
fprintf(file, "[[$ns link $node(%d) $node(%d)] queue] set maxthresh_ %f\n", edge_->src(), edge_->dst(), maxthresh_);
fprintf(file, "[[$ns link $node(%d) $node(%d)] queue] set mean_pktsize_ %d\n", edge_->src(), edge_->dst(), mean_pktsize_);
fprintf(file, "[[$ns link $node(%d) $node(%d)] queue] set q_weight_ %f\n", edge_->src(), edge_->dst(), q_weight_);
if (wait_) {
fprintf(file, "[[$ns link $node(%d) $node(%d)] queue] set queue_in_bytes_ 1\n", edge_->src(), edge_->dst());
}
fprintf(file, "[[$ns link $node(%d) $node(%d)] queue] set linterm_ %f\n", edge_->src(), edge_->dst(), linterm_);
if (setbit_) {
fprintf(file, "[[$ns link $node(%d) $node(%d)] queue] set setbit_ 1\n", edge_->src(), edge_->dst());
}
if (queue_in_bytes_) {
fprintf(file, "[[$ns link $node(%d) $node(%d)] queue] set drop_tail_ 1\n", edge_->src(), edge_->dst());
}
}
}
return 0;
}
//----------------------------------------------------------------------
// QueueHandle::property()
// - return the list of queue configuration parameters
// (properties) to be shown in the property edit window
//----------------------------------------------------------------------
const char*
QueueHandle::property() {
return getProperties(type_);
}
//----------------------------------------------------------------------
// QueueHandle::property()
// - return the list of queue configuration parameters
// (properties) to be shown in the property edit window
// - This is used if the queue type is changed to a different type
// so we can give the properties related to that specific type of
// queue to which we have switched
//----------------------------------------------------------------------
const char *
QueueHandle::getProperties(char * type) {
static char text[PROPERTY_STRING_LENGTH];
char * property_list;
// object type, id and header info
property_list = text;
sprintf(text, "{\"Queue: %s %d->%d\" title title \"QueueHandle %d-%d\"} ",
type_, edge_->src(), edge_->dst(), edge_->src(), edge_->dst());
property_list = &text[strlen(text)];
sprintf(property_list, "{\"Queue Type\" type_ drop_down_list {{%s} {DropTail FairQueue StocasticFairQueue DeficitRoundRobin RED}}} ", type);
if (strcmp(type, "DropTail") == 0) {
property_list = &text[strlen(text)];
sprintf(property_list, "{\"Maximum Queue Size\" limit_ text %d} ",
limit_);
} else if (strcmp(type, "FairQueue") == 0) {
property_list = &text[strlen(text)];
sprintf(property_list, "{\"Seconds Per Byte\" secsPerByte_ text %f} ",
secsPerByte_);
} else if (strcmp(type, "StocasticFairQueue") == 0) {
property_list = &text[strlen(text)];
sprintf(property_list, "{\"Maximum Queue Size\" maxqueue_ text %d} ",
maxqueue_);
property_list = &text[strlen(text)];
sprintf(property_list, "{\"Number of Buckets\" buckets_ text %d} ",
buckets_);
} else if (strcmp(type, "DeficitRoundRobin") == 0) {
property_list = &text[strlen(text)];
sprintf(property_list, "{\"Number of Buckets\" buckets_ text %d} ",
buckets_);
property_list = &text[strlen(text)];
sprintf(property_list, "{\"Shared Buffer Size\" blimit_ text %d} ",
blimit_);
property_list = &text[strlen(text)];
sprintf(property_list, "{\"Flow Quantum\" quantum_ text %d} ",
quantum_);
property_list = &text[strlen(text)];
sprintf(property_list, "{\"Exclude Port Number from Flow Identification\" mask_ checkbox %d} ",
mask_);
} else if (strcmp(type, "RED") == 0) {
property_list = &text[strlen(text)];
sprintf(property_list, "{\"Enable Byte Mode RED\" bytes_ checkbox %d} ",
bytes_);
property_list = &text[strlen(text)];
sprintf(property_list, "{\"Queue in Bytes\" queue_in_bytes_ checkbox %d} ",
queue_in_bytes_);
property_list = &text[strlen(text)];
sprintf(property_list, "{\"Wait Interval Between Drops\" wait_ checkbox %d} ",
wait_);
property_list = &text[strlen(text)];
sprintf(property_list, "{\"Mark Packets for Congestion Instead of Dropping\" setbit_ checkbox %d} ",
setbit_);
property_list = &text[strlen(text)];
sprintf(property_list, "{\"Use Drop Tail instead of Random Drop\" drop_tail_ checkbox %d} ",
drop_tail_);
property_list = &text[strlen(text)];
sprintf(property_list, "{\"Minimum Threshhold for Average Queue Size\" thresh_ text %g} ",
thresh_);
property_list = &text[strlen(text)];
sprintf(property_list, "{\"Maximum Threshhold for Average Queue Size\" maxthresh_ text %g} ",
maxthresh_);
property_list = &text[strlen(text)];
sprintf(property_list, "{\"Estimate for Average Queue Size\" mean_pktsize_ text %d} ",
mean_pktsize_);
property_list = &text[strlen(text)];
sprintf(property_list, "{\"Queue Weight\" q_weight_ text %g} ",
q_weight_);
property_list = &text[strlen(text)];
sprintf(property_list, "{\"Maximum Drop Probability (1/linterm_)\" linterm_ text %g} ",
linterm_);
}
return(text);
}
//----------------------------------------------------------------------
//----------------------------------------------------------------------
int QueueHandle::command(int argc, const char * const * argv) {
return TCL_OK;
}
|