⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rsvp-messages.cc

📁 rsvp and wfq patch for Netowrk Simulator 2
💻 CC
字号:
/* * Copyright (c) 1998 The University of Bonn * All rights reserved. *  * Permission to use and copy this software in source and binary forms * is hereby granted, provided that the above copyright notice, this * paragraph and the following disclaimer are retained in any copies * of any part of this software and that the University of Bonn is * acknowledged in all documentation pertaining to any such copy * or derivative work. The name of the University of Bonn may not * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,  * EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE WARRANTIES OF  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL  * THE UNIVERSITY OF BONN BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF  * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE  * SOFTWARE. */#include "rsvp-messages.h"RSVPmessage::RSVPmessage(char ty, char ttl) {  header.type = ty;  header.send_TTL = ttl;  header.length = 8;  header.conlength = sizeof(struct common_header);  objects = NULL;  tail = NULL;  con = 0;}RSVPmessage::RSVPmessage(unsigned char *cont) {  RSVPobject *n;  struct objheader *head;  struct common_header *comhead;  comhead = (struct common_header *)cont;  memcpy(&header, comhead, sizeof(struct common_header));  unsigned char *search = cont + sizeof(struct common_header);  objects = NULL;  tail = NULL;  con = 0;  while (search < cont + header.conlength) {    head = (struct objheader*)search;    switch (head->classnum) {      case 1: n = new SESSION(search); break;      case 3: n = new RSVP_HOP(search); break;      case 5: n = new TIME_VALUES(search); break;      case 6: n = new ERROR_SPEC(search); break;      case 8: n = new STYLE(search); break;      case 9: n = new FLOWSPEC(search); break;      case 10: n = new FILTER_SPEC(search); break;      case 11: n = new SENDER_TEMPLATE(search); break;      case 12: n = new SENDER_TSPEC(search); break;      case 15: n = new RESV_CONFIRM(search); break;    }    search = search + n->get_conlength();    if (tail == NULL) {      objects = n;      tail = objects;    } else {      tail->next = n;      tail = n;    }  }}/* get_first returns the first RSVPobject in the object list with   the Class-Num 'classnum'.   */RSVPobject *RSVPmessage::get_first(char classnum) {  RSVPobject *search;  search = objects;  while ((search != NULL) && (search->get_classnum() != classnum)) {    search = search->next;  }  return search;}/* delete_first deletes the first RSVPobject in the object list with   the Class-Num 'classnum'.   */void RSVPmessage::delete_first(char classnum) {  RSVPobject *temp, *search;  if (objects != NULL) {    if (objects->get_classnum() == classnum) {      temp = objects;      objects = objects->next;      header.conlength -= temp->get_conlength();      header.length -= temp->get_length();      delete temp;    } else {      search = objects;      while ((search->next != NULL) && 	     (search->next->get_classnum() != classnum)) {	search = search->next;      }      if (search->next != NULL) {	temp = search->next;	search->next = search->next->next;	header.conlength -= temp->get_conlength();	header.length -= temp->get_length();	delete temp;      }    }  }}/* delete_objects() deletes all objects from the object list */void RSVPmessage::delete_objects() {  RSVPobject *temp;  while (objects != NULL) {    temp = objects;    objects = objects->next;    delete temp;  }  header.conlength = sizeof(struct common_header);  header.length = 8;}/* Adds an RSVP object to the end of the message's object list */void RSVPmessage::add_object(RSVPobject *obj) {  if (objects == NULL) {    objects = obj;  } else {    tail->next = obj;  }  tail = obj;  header.conlength += obj->get_conlength();  header.length += obj->get_length();}unsigned char *RSVPmessage::get_contents() {  if (con) {    delete[] contents;  }  contents = new unsigned char[header.conlength];  struct common_header *comhead = (struct common_header *)contents;  memcpy(comhead, &header, sizeof(struct common_header));  unsigned char *pos = contents + sizeof(struct common_header);  RSVPobject *search = objects;  while (search != NULL) {    memcpy(pos, search->get_contents(), search->get_conlength());    pos = pos + search->get_conlength();    search = search->next;  }  con = 1;  return contents;}/* Dump the RSVP message (possible debug output) */void RSVPmessage::dump_message() {  printf("RSVPmessage:  Type: %d  send_TTL: %d  length: %d  conlength: %d\n",	 header.type, header.send_TTL, header.length, header.conlength);  RSVPobject *search;  search = objects;  while (search != NULL) {    search->dump_object();    search = search->next;  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -