umts-ip-interface.cc

00001 /*
00002  * Copyright (c) 2007 Regents of the SIGNET lab, University of Padova.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the University of Padova (SIGNET lab) nor the 
00014  *    names of its contributors may be used to endorse or promote products 
00015  *    derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
00018  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 
00019  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
00020  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
00021  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00022  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
00023  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
00024  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
00025  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
00026  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
00027  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 #include "umts-ip-interface.h"
00031 #include"umts-headers.h"
00032 #include<ip.h>
00033 #include <algorithm>    
00034 
00035 static class UmtsIPInterfaceModuleClass : public TclClass {
00036 public:
00037   UmtsIPInterfaceModuleClass() : TclClass("Module/IP/Interface/UMTS") {}
00038   TclObject* create(int, const char*const*) {
00039     return (new UmtsIPInterfaceModule);
00040 
00041   }
00042 } class_Umtsipinterface_module;
00043 
00044 
00045 
00046 UmtsIPInterfaceModule::UmtsIPInterfaceModule()
00047 {
00048   
00049 }
00050 
00051 UmtsIPInterfaceModule::~UmtsIPInterfaceModule()
00052 {
00053 
00054 }
00055 
00056 
00057 int UmtsIPInterfaceModule::command(int argc, const char*const* argv)
00058 {
00059   Tcl& tcl = Tcl::instance();
00060   if(argc == 2)
00061     {
00062       if (strcasecmp(argv[1],"getCodeId")==0)
00063         {
00064           tcl.resultf("%d", getCode(ipAddr_));
00065           return TCL_OK;
00066         }
00067     }
00068   else if (argc == 3) 
00069     {
00070       if (strcasecmp(argv[1],"setCodeId")==0)
00071         {
00072           addIpCode(ipAddr_, atoi(argv[2]));
00073           return TCL_OK;
00074         }
00075     }
00076 
00077   return IPInterfaceModule::command(argc, argv);
00078 }
00079 
00080 
00081 void UmtsIPInterfaceModule::recv(Packet *p)
00082 {
00083   hdr_ip *iph = HDR_IP(p);
00084   hdr_cmn *ch = HDR_CMN(p);
00085   hdr_umtsphy * uh = HDR_UMTSPHY(p);
00086 
00087   if(ch->direction() == hdr_cmn::DOWN)
00088     {
00089       // next hop should be an UMTS node
00090       // This is the Right Thing if we're at the BS
00091       // If we're at the ME, this field will be overwritten
00092       // so in current implementation no harm will be done.
00093       // I admit this is weird :-/
00094       uh->me_code_id = getCode(ch->next_hop_);
00095     }
00096   IPInterfaceModule::recv(p);
00097 }
00098 
00099 
00100 int UmtsIPInterfaceModule::getCode(nsaddr_t ipaddr)
00101 {
00102   IpCodeList::iterator res;
00103   IpCode ic(ipaddr);
00104   res = find(ipclist.begin(), ipclist.end(), ic);
00105   
00106   if (res == ipclist.end())
00107     return -1;
00108   else 
00109     return res->code;
00110 }
00111 
00112 
00113 void UmtsIPInterfaceModule::addIpCode(nsaddr_t ipaddr, int code)
00114 {
00115   // This implementation does not keep the list sorted...
00116   IpCode ic(ipaddr, code);
00117   ipclist.push_front(ic); 
00118   
00119 }
00120 
00121 
00122 // nsaddr_t  UmtsIPInterfaceModule::ipAddrCounter = UMTS_START_IP_ADDRESS;
00123 // nsaddr_t  UmtsIPInterfaceModule::ipSubNet      = UMTS_SUBNET_MASK;

Generated on Wed Nov 26 15:47:29 2008 for NS-MIRACLE library by  doxygen 1.5.2