Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

VirtualCircuitTableCommand.cpp

Go to the documentation of this file.
00001 #ifdef TEST
00002 
00003 #include "headers.h"
00004 
00005 const static string virtualCircuitTableCommandString = "vct";
00006 const static string addCommandString = "add";
00007 const static string lookupCommandString = "lookup";
00008 const static string removeCommandString = "remove";
00009 
00010 VirtualCircuitTableCommand::VirtualCircuitTableCommand() : Command() {
00011     Node* myself = new Node();
00012     m_vct = new VirtualCircuitTable(myself);
00013 }
00014 
00015 
00016 void
00017 VirtualCircuitTableCommand::getHelp(std::ostream& s) {
00018     s << virtualCircuitTableCommandString << "\n"
00019         << "  " << addCommandString << "<src IP> <src VCN> <dest IP> <dest VCN>" << "\n"
00020         << "  " << lookupCommandString << "<src IP> <src VCN>\n" 
00021         << "  " << removeCommandString << "<src IP> <src VCN>\n";
00022 }
00023 
00024 
00025 void
00026 VirtualCircuitTableCommand::getHtmlInterface(std::ostream& s) {
00027     s << "<h2>Virtual Circuit Table</h2>";
00028     beginUl(s);
00029     generateHtmlSubcmd(s, showCommandString, "Show");
00030     generateHtmlSubcmdArg4(s, addCommandString, 
00031                             "Add node to table, Src IP address:",
00032                             "Src VCN:",
00033                             "Dest IP Addr:",
00034                             "Dest VCN:",
00035                             "Add");
00036     generateHtmlSubcmdArg2(s, lookupCommandString, "Lookup node in table, Src IP address:", "Src VCN: ", "Lookup");
00037     generateHtmlSubcmdArg2(s, removeCommandString, "Remove node in table, Src IP address:", "Src VCN: ", "Remove");
00038     endUl(s);
00039 }
00040 
00041 
00042 void
00043 VirtualCircuitTableCommand::run(std::ostream& s) {
00044     if (m_args[1] == showCommandString) {
00045         s << *m_vct;
00046     }
00047     else if (m_args[1] == addCommandString) {
00048         Node* srcNode = new Node();
00049         IpAddress ip(m_args[2]);
00050         SocketAddress socketAddress(ip, DEFAULT_PORT);
00051         srcNode->setSocketAddress(&socketAddress);
00052         int srcVcn = atoi(m_args[3].c_str());
00053         Node* destNode = new Node();
00054         socketAddress.setIpAddress(IpAddress(m_args[4]));
00055         destNode->setSocketAddress(&socketAddress);
00056         int destVcn = atoi(m_args[5].c_str());
00057 
00058         m_vct->add(srcNode, 
00059             srcVcn,
00060             destNode, 
00061             destVcn);
00062     }
00063     else if (m_args[1] == lookupCommandString) {
00064         VirtualCircuitTableEntry* vcEntry = NULL;
00065         Node srcNode;
00066         IpAddress ip(m_args[2]);
00067         SocketAddress socketAddress(ip, DEFAULT_PORT);
00068         srcNode.setSocketAddress(&socketAddress);
00069         int srcVcn = atoi(m_args[3].c_str());
00070         if (vcEntry = m_vct->findBySrc(&srcNode, srcVcn)) {
00071             s << "\n" << "Entry found:" << "\n" << *vcEntry << "\n";
00072         }
00073         else {
00074             s << "\n" << "Entry NOT found" << "\n";
00075         }
00076     }
00077     else if (m_args[1] == removeCommandString) {
00078         Node srcNode;
00079         IpAddress ip(m_args[2]);
00080         SocketAddress socketAddress(ip, DEFAULT_PORT);
00081         srcNode.setSocketAddress(&socketAddress);
00082         int srcVcn = atoi(m_args[3].c_str());
00083         if (m_vct->remove(&srcNode, srcVcn)) {
00084             s << "\n" << "Entry removed" << "\n";
00085         }
00086         else {
00087             s << "\n" << "Failed to remove entry" << "\n";
00088         }
00089     }
00090 }
00091 
00092 
00093 string
00094 VirtualCircuitTableCommand::getCommandString() {
00095     return virtualCircuitTableCommandString;
00096 }
00097 
00098 #endif
00099 

Generated at Thu Jul 11 13:31:53 2002 for Peekabooty by doxygen1.2.9 written by Dimitri van Heesch, © 1997-2001