Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

rtProtoDV.cc

Go to the documentation of this file.
00001 /* -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
00002 /*
00003  * rtProtoDV.cc
00004  *
00005  * Copyright (C) 1997 by USC/ISI
00006  * All rights reserved.                                            
00007  *                                                                
00008  * Redistribution and use in source and binary forms are permitted
00009  * provided that the above copyright notice and this paragraph are
00010  * duplicated in all such forms and that any documentation, advertising
00011  * materials, and other materials related to such distribution and use
00012  * acknowledge that the software was developed by the University of
00013  * Southern California, Information Sciences Institute.  The name of the
00014  * University may not be used to endorse or promote products derived from
00015  * this software without specific prior written permission.
00016  * 
00017  * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
00018  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
00019  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00020  * 
00021  */
00022 
00023 #ifndef lint
00024 static const char rcsid[] =
00025     "@(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/routing/rtProtoDV.cc,v 1.8 2000/09/01 03:04:06 haoboy Exp $ (USC/ISI)";
00026 #endif
00027 
00028 #include "agent.h"
00029 #include "rtProtoDV.h"
00030 
00031 int hdr_DV::offset_;
00032 
00033 static class rtDVHeaderClass : public PacketHeaderClass {
00034 public:
00035         rtDVHeaderClass() : PacketHeaderClass("PacketHeader/rtProtoDV",
00036                                               sizeof(hdr_DV)) {
00037                 bind_offset(&hdr_DV::offset_);
00038         } 
00039 } class_rtProtoDV_hdr;
00040 
00041 static class rtProtoDVclass : public TclClass {
00042 public:
00043         rtProtoDVclass() : TclClass("Agent/rtProto/DV") {}
00044         TclObject* create(int, const char*const*) {
00045                 return (new rtProtoDV);
00046         }
00047 } class_rtProtoDV;
00048 
00049 
00050 int rtProtoDV::command(int argc, const char*const* argv)
00051 {
00052         if (strcmp(argv[1], "send-update") == 0) {
00053                 ns_addr_t dst;
00054                 dst.addr_ = atoi(argv[2]);
00055                 dst.port_ = atoi(argv[3]);
00056                 u_int32_t mtvar = atoi(argv[4]);
00057                 u_int32_t size  = atoi(argv[5]);
00058                 sendpkt(dst, mtvar, size);
00059                 return TCL_OK;
00060         }
00061         return Agent::command(argc, argv);
00062 }
00063 
00064 void rtProtoDV::sendpkt(ns_addr_t dst, u_int32_t mtvar, u_int32_t size)
00065 {
00066         daddr() = dst.addr_;
00067         dport() = dst.port_;
00068         size_ = size;
00069         
00070         Packet* p = Agent::allocpkt();
00071         hdr_DV *rh = hdr_DV::access(p);
00072         rh->metricsVar() = mtvar;
00073 
00074         target_->recv(p);
00075 }
00076 
00077 void rtProtoDV::recv(Packet* p, Handler*)
00078 {
00079         hdr_DV* rh = hdr_DV::access(p);
00080         hdr_ip* ih = hdr_ip::access(p);
00081         Tcl::instance().evalf("%s recv-update %d %d", name(),
00082                               ih->saddr(), rh->metricsVar());
00083         Packet::free(p);
00084 }

Generated on Tue Apr 20 12:14:30 2004 for NS2.26SourcesOriginal by doxygen 1.3.3