classifier-mac.cc
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:3k
源码类别:

通讯编程

开发平台:

Visual C++

  1. /* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
  2. /*
  3.  * Copyright (c) 1996-1997 Regents of the University of California.
  4.  * All rights reserved.
  5.  * 
  6.  * Redistribution and use in source and binary forms, with or without
  7.  * modification, are permitted provided that the following conditions
  8.  * are met:
  9.  * 1. Redistributions of source code must retain the above copyright
  10.  *    notice, this list of conditions and the following disclaimer.
  11.  * 2. Redistributions in binary form must reproduce the above copyright
  12.  *    notice, this list of conditions and the following disclaimer in the
  13.  *    documentation and/or other materials provided with the distribution.
  14.  * 3. All advertising materials mentioning features or use of this software
  15.  *    must display the following acknowledgement:
  16.  *  This product includes software developed by the MASH Research
  17.  *  Group at the University of California Berkeley.
  18.  * 4. Neither the name of the University nor of the Research Group may be
  19.  *    used to endorse or promote products derived from this software without
  20.  *    specific prior written permission.
  21.  * 
  22.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  23.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  26.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  28.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  29.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  31.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  32.  * SUCH DAMAGE.
  33.  *
  34.  * Contributed by Giao Nguyen, http://daedalus.cs.berkeley.edu/~gnguyen
  35.  */
  36. #ifndef lint
  37. static const char rcsid[] =
  38.     "@(#) $Header: /cvsroot/nsnam/ns-2/classifier/classifier-mac.cc,v 1.15 1999/01/04 19:58:56 haldar Exp $ (UCB)";
  39. #endif
  40. #include "packet.h"
  41. #include "mac.h"
  42. #include "classifier.h"
  43. class MacClassifier : public Classifier {
  44. public:
  45. MacClassifier() : bcast_(0) {
  46. bind("bcast_", &bcast_);
  47. }
  48. void recv(Packet*, Handler*);
  49. int bcast_;
  50. };
  51. static class MacClassifierClass : public TclClass {
  52. public:
  53. MacClassifierClass() : TclClass("Classifier/Mac") {}
  54. TclObject* create(int, const char*const*) {
  55. return (new MacClassifier());
  56. }
  57. } class_mac_classifier;
  58. void MacClassifier::recv(Packet* p, Handler*)
  59. {
  60. Mac* mac;
  61. hdr_mac* mh = HDR_MAC(p);
  62. if (bcast_ || mh->macDA() == BCAST_ADDR || (mac = (Mac *)find(p)) == 0) {
  63. // Replicate packets to all slots (broadcast)
  64. int macSA = mh->macSA();
  65. for (int i = 0; i < maxslot_; ++i) {
  66. if ((mac = (Mac *)slot_[i]) && mac->addr() != macSA) 
  67. mac->recv(p->copy(), 0);
  68. }
  69. if (maxslot_ >= 0) {
  70. mac= (Mac *)slot_[maxslot_];
  71. if (mac->addr() != macSA) { 
  72. mac->recv(p, 0);
  73. return;
  74. }
  75. }
  76. Packet::free(p);
  77. return;
  78. }
  79. mac->recv(p, 0);
  80. }