📄 bss_ragent.cc
字号:
/* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- *//* * Copyright (c) 1997 Regents of the University of 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 Computer Systems * Engineering Group at Lawrence Berkeley Laboratory. * 4. Neither the name of the University nor of the Laboratory 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. */extern "C" {#include <stdarg.h>#include <float.h>};#include <string.h>#include <stdlib.h>#include <stdio.h>#include <cmu-trace.h>#include <address.h>#include <mobilenode.h>#include "bss_ragent.h"////////////////////////////////////////////////////////////////////////////////////static int diff_subnet(int src, int dst) { char* srcnet = Address::instance().get_subnetaddr(src); char* dstnet = Address::instance().get_subnetaddr(dst); if (srcnet != NULL) { if (dstnet != NULL) { if (strcmp(dstnet, srcnet) != 0) { delete [] dstnet; return 1; } delete [] dstnet; } delete [] srcnet; } return 0;}////////////////////////////////////////////////////////////////////////////////////static class BSS_RAgent_Class: public TclClass {public: BSS_RAgent_Class(): TclClass("Agent/BSS") { } TclObject* create(int, const char* const*) { return (new BSS_RAgent()); }} class_bss_ragent;////////////////////////////////////////////////////////////////////////////////////void BSS_RAgent::trace(char* fmt, ...){ va_list ap; if (!tracetarget) return; va_start(ap, fmt); vsprintf(tracetarget->buffer(), fmt, ap); tracetarget->dump(); va_end(ap);}void BSS_RAgent::recv(Packet* p, Handler* h){ hdr_cmn* cmh = HDR_CMN(p); hdr_ip* iph = HDR_IP(p); int dst = Address::instance().get_nodeaddr(iph->daddr()); int src = Address::instance().get_nodeaddr(iph->saddr()); assert(node_ && mac_); int me = node_->address(); /* Remember that I'm a router! I work with IP addresses * only; ns routing happens via (a chain) of classifiers * based on the assumption that there is only one node at * the end of every link, it doesn't work very well for * wireless/ethernet scenarios => having a real router for * them; given the way a wireless node is organized, we * end up essentially being the default gateway => only * one wireless NIC per node; my routing policy is rather * simple for now! if I'm a station, my default gateway is * the DS; if I'm an DS, hey I can talk to anyone in the * BSS, and each of them could be a gateway => I need a real * routing table with a real routing protocol; trying to * keep this simple for now => DS won't route via the BSS * and will drop such packets */ if (dst == me) { /* locally or remotely originated packet * intended for this node; the port_demux * didn't catch it => either there is no * agent to sink this pkt, or its a routing * update! we aren't running a real routing * protocol which sends routing updates etc. * here! so either way this pkt can be dropped! */ drop(p, "BSSR"); return; } if (diff_subnet(me, dst)) { if (mac_->addr() == mac_->bss_id()) { /* see comment above - DS doesn't route here! */ drop(p, DROP_RTR_NO_ROUTE); return; } /* Packet I'm forwarding... check the TTL; * discard if 0; xxxamanxxx: am assuming * that IP header has already been added * to the pkt size even if I'm the source * - the original dsdv agent code didn't * think so! */ if ((src != me) && (--iph->ttl_ == 0)) { drop(p, DROP_RTR_TTL); return; } /* DS is my defacto router! I don't need to * know its IP address though :-) */ cmh->addr_type_ = NS_AF_ILINK; cmh->next_hop_ = mac_->bss_id(); } else { cmh->addr_type_ = NS_AF_INET; cmh->next_hop_ = dst; } send(p, h); return;}int BSS_RAgent::command(int argc, const char* const* argv){ if (argc == 3) { TclObject *obj; if ((obj = TclObject::lookup(argv[2])) == 0) { fprintf (stderr, "%s: %s lookup of %s failed\n", __FILE__, argv[1], argv[2]); return TCL_ERROR; } if (strcasecmp(argv[1], "tracetarget") == 0) { tracetarget = (Trace *)obj; return TCL_OK; } else if (strcasecmp(argv[1], "node") == 0) { node_ = (MobileNode*)obj; return TCL_OK; } else if (strcasecmp(argv[1], "mac") == 0) { mac_ = (Mac802_11*)obj; return TCL_OK; } } return (Agent::command (argc, argv));}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -