classifier-mac.cc

Go to the documentation of this file.
00001 /* -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
00002 /*
00003  * Copyright (c) 1996-1997 Regents of the University of California.
00004  * All rights reserved.
00005  * 
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  * 1. Redistributions of source code must retain the above copyright
00010  *    notice, this list of conditions and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright
00012  *    notice, this list of conditions and the following disclaimer in the
00013  *    documentation and/or other materials provided with the distribution.
00014  * 3. All advertising materials mentioning features or use of this software
00015  *    must display the following acknowledgement:
00016  *  This product includes software developed by the MASH Research
00017  *  Group at the University of California Berkeley.
00018  * 4. Neither the name of the University nor of the Research Group may be
00019  *    used to endorse or promote products derived from this software without
00020  *    specific prior written permission.
00021  * 
00022  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00023  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00024  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00025  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00026  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00027  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00028  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00029  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00031  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00032  * SUCH DAMAGE.
00033  *
00034  * Contributed by Giao Nguyen, http://daedalus.cs.berkeley.edu/~gnguyen
00035  */
00036 
00037 #ifndef lint
00038 static const char rcsid[] =
00039     "@(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/classifier/classifier-mac.cc,v 1.15 1999/01/04 19:58:56 haldar Exp $ (UCB)";
00040 #endif
00041 
00042 #include "packet.h"
00043 #include "mac.h"
00044 #include "classifier.h"
00045 
00046 class MacClassifier : public Classifier {
00047 public:
00048     MacClassifier() : bcast_(0) {
00049         bind("bcast_", &bcast_);
00050     }
00051     void recv(Packet*, Handler*);
00052     int bcast_;
00053 };
00054 
00055 static class MacClassifierClass : public TclClass {
00056 public:
00057     MacClassifierClass() : TclClass("Classifier/Mac") {}
00058     TclObject* create(int, const char*const*) {
00059         return (new MacClassifier());
00060     }
00061 } class_mac_classifier;
00062 
00063 
00064 void MacClassifier::recv(Packet* p, Handler*)
00065 {
00066     Mac* mac;
00067     hdr_mac* mh = HDR_MAC(p);
00068 
00069     if (bcast_ || mh->macDA() == BCAST_ADDR || (mac = (Mac *)find(p)) == 0) {
00070         // Replicate packets to all slots (broadcast)
00071         int macSA = mh->macSA();
00072         for (int i = 0; i < maxslot_; ++i) {
00073             if ((mac = (Mac *)slot_[i]) && mac->addr() != macSA) 
00074                 mac->recv(p->copy(), 0);
00075         }
00076         if (maxslot_ >= 0) {
00077             mac= (Mac *)slot_[maxslot_];
00078             if (mac->addr() != macSA) { 
00079                 mac->recv(p, 0);
00080                 return;
00081             }
00082         }
00083         Packet::free(p);
00084         return;
00085     }
00086     mac->recv(p, 0);
00087 }

Generated on Tue Mar 6 16:47:43 2007 for ns2 Network Simulator 2.29 by  doxygen 1.4.6