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

mcast_ctrl.cc

Go to the documentation of this file.
00001 /* -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
00002 /*
00003  * mcast_ctrl.cc
00004  * Copyright (C) 1997 by USC/ISI
00005  * All rights reserved.                                            
00006  *                                                                
00007  * Redistribution and use in source and binary forms are permitted
00008  * provided that the above copyright notice and this paragraph are
00009  * duplicated in all such forms and that any documentation, advertising
00010  * materials, and other materials related to such distribution and use
00011  * acknowledge that the software was developed by the University of
00012  * Southern California, Information Sciences Institute.  The name of the
00013  * University may not be used to endorse or promote products derived from
00014  * this software without specific prior written permission.
00015  * 
00016  * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
00017  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
00018  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00019  *
00020  * Contributed by Polly Huang (USC/ISI), http://www-scf.usc.edu/~bhuang
00021  */
00022 
00023 #ifndef lint
00024 static const char rcsid[] =
00025     "@(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/mcast/mcast_ctrl.cc,v 1.6 2000/09/01 03:04:06 haoboy Exp $ (LBL)";
00026 #endif
00027 
00028 #include "agent.h"
00029 #include "packet.h"
00030 #include "mcast_ctrl.h"
00031 
00032 class mcastControlAgent : public Agent {
00033 public:
00034         mcastControlAgent() : Agent(PT_NTYPE) {
00035                 bind("packetSize_", &size_);
00036         }
00037 
00038         void recv(Packet* pkt, Handler*) {
00039                 hdr_mcast_ctrl* ph = hdr_mcast_ctrl::access(pkt);
00040                 hdr_cmn* ch = hdr_cmn::access(pkt);
00041                 // Agent/Mcast/Control instproc recv type from src group iface
00042                 Tcl::instance().evalf("%s recv %s %d %d", name(),
00043                                       ph->type(), ch->iface(), ph->args());
00044                 Packet::free(pkt);
00045         }
00046 
00047         /*
00048          * $proc send $type $src $group
00049          */
00050 
00051 #define CASE(c,str,type)                                                \
00052                 case (c):       if (strcmp(argv[2], (str)) == 0) {      \
00053                         type_ = (type);                                 \
00054                         break;                                          \
00055                 } else {                                                \
00056                         /*FALLTHROUGH*/                                 \
00057                 }
00058 
00059         int command(int argc, const char*const* argv) {
00060                 if (argc == 4) {
00061                         if (strcmp(argv[1], "send") == 0) {
00062                                 switch (*argv[2]) {
00063                                         CASE('p', "prune", PT_PRUNE);
00064                                         CASE('g', "graft", PT_GRAFT);
00065                                         CASE('X', "graftAck", PT_GRAFTACK);
00066                                         CASE('j', "join",  PT_JOIN);
00067                                         CASE('a', "assert", PT_ASSERT);
00068                                 default:
00069                                         Tcl& tcl = Tcl::instance();
00070                                         tcl.result("invalid control message");
00071                                         return (TCL_ERROR);
00072                                 }
00073                                 Packet* pkt = allocpkt();
00074                                 hdr_mcast_ctrl* ph=hdr_mcast_ctrl::access(pkt);
00075                                 strcpy(ph->type(), argv[2]);
00076                                 ph->args()  = atoi(argv[3]);
00077                                 send(pkt, 0);
00078                                 return (TCL_OK);
00079                         }
00080                 }
00081                 return (Agent::command(argc, argv));
00082         }
00083 };
00084 
00085 //
00086 // Now put the standard OTcl linkage templates here
00087 //
00088 int hdr_mcast_ctrl::offset_;
00089 static class mcastControlHeaderClass : public PacketHeaderClass {
00090 public:
00091         mcastControlHeaderClass() : PacketHeaderClass("PacketHeader/mcastCtrl",
00092                                              sizeof(hdr_mcast_ctrl)) {
00093                 bind_offset(&hdr_mcast_ctrl::offset_);
00094         }
00095 } class_mcast_ctrl_hdr;
00096 
00097 static class mcastControlClass : public TclClass {
00098 public:
00099         mcastControlClass() : TclClass("Agent/Mcast/Control") {}
00100         TclObject* create(int, const char*const*) {
00101                 return (new mcastControlAgent());
00102         }
00103 } class_mcast_ctrl;

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