classifier-nix.cc

Go to the documentation of this file.
00001 /* -*-  Mode:C++; c-basic-offset:2; tab-width:2; indent-tabs-mode:f -*- */
00002 
00003 /*
00004  * classifier-nix.cc
00005  * Copyright (C) 2000 by the University of Southern California
00006  * $Id: classifier-nix.cc,v 1.6 2005/08/25 18:58:09 johnh Exp $
00007  *
00008  * This program is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU General Public License,
00010  * version 2, as published by the Free Software Foundation.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License along
00018  * with this program; if not, write to the Free Software Foundation, Inc.,
00019  * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00020  *
00021  *
00022  * The copyright of this module includes the following
00023  * linking-with-specific-other-licenses addition:
00024  *
00025  * In addition, as a special exception, the copyright holders of
00026  * this module give you permission to combine (via static or
00027  * dynamic linking) this module with free software programs or
00028  * libraries that are released under the GNU LGPL and with code
00029  * included in the standard release of ns-2 under the Apache 2.0
00030  * license or under otherwise-compatible licenses with advertising
00031  * requirements (or modified versions of such code, with unchanged
00032  * license).  You may copy and distribute such a system following the
00033  * terms of the GNU GPL for this module and the licenses of the
00034  * other code concerned, provided that you include the source code of
00035  * that other code when and as the GNU GPL requires distribution of
00036  * source code.
00037  *
00038  * Note that people who make modified versions of this module
00039  * are not obligated to grant this special exception for their
00040  * modified versions; it is their choice whether to do so.  The GNU
00041  * General Public License gives permission to release a modified
00042  * version without this exception; this exception also makes it
00043  * possible to release a modified version which carries forward this
00044  * exception.
00045  *
00046  */
00047 
00048 /*
00049  * NixVector classifier for stateless routing
00050  * contributed to ns from 
00051  * George F. Riley, Georgia Tech, Spring 2000
00052  *
00053  */
00054 
00055 #include "config.h"
00056 #ifdef HAVE_STL
00057 
00058 
00059 #include <stdio.h>
00060 
00061 #include "ip.h"
00062 #include "nixvec.h"
00063 #include "classifier-nix.h"
00064 #include "hdr_nv.h"
00065 
00066 /* Define the TCL Class */
00067 static class NixClassifierClass : public TclClass {
00068 public:
00069     NixClassifierClass() : TclClass("Classifier/Nix") {}
00070     TclObject* create(int, const char*const*) {
00071         return (new NixClassifier());
00072     }
00073 } class_nix_classifier;
00074 
00075 
00076 
00077 /****************** NixClassifier Methods ************/
00078 NsObject* NixClassifier::find(Packet* p)
00079 {
00080     if (m_NodeId == NODE_NONE)
00081         {
00082             printf("NixClassifier::find(), Unknown node id\n");
00083             return(NULL);
00084         }
00085     NixNode* pN = NixNode::GetNodeObject(m_NodeId);
00086     hdr_ip* ip = hdr_ip::access(p);
00087     if ((nodeid_t)ip->daddr() == pN->Id())
00088         { // Arrived at destination, pass on to the dmux object
00089             if(0)printf("Returning Dmux objet %p\n", m_Dmux);
00090             return m_Dmux;
00091         }
00092     hdr_nv* nv = hdr_nv::access(p);
00093     NixVec* pNv = nv->nv();
00094     if (pNv == NULL)
00095         {
00096             printf("Error! NixClassifier %s called with no NixVector\n", name());
00097             return(NULL);
00098         }
00099     if (pN == NULL)
00100         {
00101             printf("NixClassifier::find(), can't find node id %ld\n", m_NodeId);
00102             return(NULL);
00103         }
00104     Nix_t Nix = pNv->Extract(pN->GetNixl(), nv->used()); // Get the next nix
00105   nodeid_t n = pN->GetNeighbor(Nix,pNv); // this is just for debug print
00106   NsObject* nsobj = pN->GetNsNeighbor(Nix);
00107     if(0)printf("Classifier %s, Node %ld next hop %ld (%s)\n",
00108                  name(), pN->Id(), n, nsobj->name());
00109     return(nsobj); // And return the nexthop head object
00110 }
00111 
00112 int NixClassifier::command(int argc, const char*const* argv)
00113 {
00114     if (argc == 3 && strcmp(argv[1],"set-node-id") == 0)
00115         {
00116             m_NodeId = atoi(argv[2]);
00117             return(TCL_OK);
00118         }
00119     if (argc == 4 && strcmp(argv[1],"install") == 0)
00120         {
00121             int target = atoi(argv[2]);
00122             NixNode* pN = NixNode::GetNodeObject(m_NodeId);
00123             if (pN)
00124                 {
00125                     if(0)printf("%s NixClassifier::Command node %ld install %s %s\n",
00126                                  name(), pN->Id(), argv[2], argv[3]);
00127                     if ((nodeid_t)target == pN->Id())
00128                         { // This is the only case we care about, need to note the dmux obj
00129                             m_Dmux = (NsObject*)TclObject::lookup(argv[3]);
00130                             if(0)printf("m_Dmux obj is %p\n", m_Dmux);
00131                         }
00132                 }
00133             return(TCL_OK);
00134         }
00135     return (Classifier::command(argc, argv));
00136 }
00137  
00138 #endif // HAVE_STL

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