Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need a little help with homework for c++ data structures/algorithms project. T

ID: 3689784 • Letter: I

Question

I need a little help with homework for c++ data structures/algorithms project. This is a Router Simulation as client of generic HashTable. There are two files, the first I will post so you can see. Solutions needed where //TBS is seen.

file should contain implementations of Router methods. The startup file contains all of the boiler plate and some other methods already completed.

---------------------------------------------------

#include <fstream>
#include <iomanip>
#include <cstring>
#include <ipr.h>

void Router::Insert(const ipString& dS, const ipString& rS, bool verify)
{
// TBS
}

void Router::Remove (const ipString& dS)
{
// TBS
}

void Router::Go (const char* msgfile, bool verbose, const char* logfile)
{
std::cout << " Router simulation started ";
std::ifstream fin;
fin.open(msgfile);
if (fin.fail())
{
std::cerr << "** Router: unable to open msg file " << msgfile << ' '
<< " Go() aborted ";
return;
}
fin >> std::hex;
std::ofstream fout;
std::ostream * optr = &std::cout;
if (verbose)
{
if (logfile != nullptr)
{
fout.open(logfile);
if (fout.fail())
{
std::cerr << "** Router: unable to open log file " << logfile << ' '
<< " Go() aborted ";
return;
}
optr = &fout;
}
}
ipClass ipC;
ipString dS;
ipNumber dN, rN, netID, hostID;
fsu::String msgID;
size_t packets(0), routed(0), routedA(0), routedB(0), routedC(0), rejected(0)
, bad(0);
(*optr) << std::hex << std::uppercase;
fin >> dS >> msgID;
while (!fin.fail())
{
++packets;

// TBS

fin >> dS >> msgID;
} // end while()
fin.close();
if (logfile == nullptr)
{
// set cout back to normal
std::cout << std::dec << std::setfill(' ');
}
else
{
// close the log file
fout.clear();
fout.close();
}
std::cout << " Packets processed: " << packets << ' '
<< " Packets routed: " << routed << ' '
<< " route class A: " << routedA << ' '
<< " route class B: " << routedB << ' '
<< " route class C: " << routedC << ' '
<< " Packets rejected: " << rejected << ' '
<< " Packets bad: " << bad << ' ';
std::cout << " Router simulation stopped ";
if (routedA + routedB + routedC != routed)
std::cout << " ** Processing logic error: route class imbalance ";
if (routed + rejected + bad != packets)
std::cout << " ** Processing logic error: packets not accounted for ";
if (logfile != nullptr)
std::cout << " Routing log written to " << logfile << ' ';
return;
} // end Router::Go()


// ***********************************************
// below this sign should not require modification
// ***********************************************

Router::Router (size_t sizeEstimate) : tablePtr_(0)
{
ipHash iph;
tablePtr_ = new TableType (sizeEstimate, iph);
}

Router::~Router ()
{
delete tablePtr_;
}

void Router::Load (const char* loadfile)
{
std::ifstream in1;
in1.open (loadfile);
if (in1.fail())
if (in1.fail())
{
std::cerr << "** Router: unable to open file " << loadfile << ' '
<< " Load() aborted ";
return;
}
in1 >> std::hex;
EntryType::KeyType key;
EntryType::DataType data;
while (in1 >> key)
{
in1 >> data;
tablePtr_->Insert(key, data);
}
in1.close();
std::cout << " Load() completed ";
} // end Router::Load()

void Router::Save (const char* savefile)
{
std::ofstream out1;
out1.open (savefile);
if (out1.fail())
{
std::cerr << "** Router: unable to open file " << savefile << ' '
<< " Save() aborted ";
return;
}

TableType::Iterator i;
out1 << std::uppercase << std::hex << std::setfill('0');
for (i = tablePtr_->Begin(); i != tablePtr_->End(); ++i)
{
out1 << std::setw(8) << (*i).key_ << ' ' << std::setw(8) << (*i).data_ << '
';
}
out1.close();
std::cout << " Save() completed ";
} // end Router::Save()

void Router::Clear()
{
tablePtr_->Clear();
}

void Router::Dump(const char* dumpfile)
{
if (dumpfile == 0)
{
std::cout.setf(std::ios::uppercase);
std::cout << " Size(): " << std::dec << tablePtr_->Size() << std::hex
<< " Dump(): ";
std::cout.fill('0');
tablePtr_->Dump(std::cout,8,8);
std::cout.fill(' ');
std::cout.setf(std::ios::dec, std::ios::basefield);
}

else
{
std::ofstream out1;
out1.open(dumpfile);
if (out1.fail())
{
std::cerr << "** Router: failure to open dump file " << dumpfile << ' '
<< " Dump() aborted ";
return;
}
out1.setf(std::ios::uppercase);
out1 << " Size(): " << std::dec << tablePtr_->Size() << std::hex
<< " Dump(): ";

out1.fill('0');
tablePtr_->Dump(out1,8,8);
out1.close();
}
} // end Router::Dump()

void Router::Analysis()
{
tablePtr_->Analysis(std::cout);
}

void Router::Rehash(size_t numBuckets)
{
tablePtr_->Rehash(numBuckets);
}

size_t ipHash::operator () (const ipNumber& ipn) const
{
return hashfunction::KISS (ipn);
}

Explanation / Answer

package simulator_; import java.awt.peer.TextComponentPeer; import java.io.IOException; import jns.Simulator; import jns.element.DuplexInterface; import jns.element.DuplexLink; import jns.element.Interface; import jns.element.Link; import jns.element.Node; import jns.trace.Event; import jns.trace.Trace; import jns.util.IPAddr; public class simu { public static void main(String[] args) { Simulator sim=Simulator.getInstance(); Node src=new Node("Source node"); Node router=new Node("Router"); Node dest=new Node("Destination node"); sim.attach(src); sim.attach(router); sim.attach(dest); Interface src_iface=new DuplexInterface(new IPAddr(192,168,1,10)); src.attach(src_iface); sim.attach(src_iface); Interface dest_iface=new DuplexInterface(new IPAddr(128,116,11,20)); dest.attach(dest_iface); sim.attach(dest_iface); Interface route_iface192=new DuplexInterface(new IPAddr(192,168,1,1)); Interface route_iface128=new DuplexInterface(new IPAddr(128,116,11,1)); router.attach(route_iface192); router.attach(route_iface128); sim.attach(route_iface192); sim.attach(route_iface128); Link link_src_router=new DuplexLink(1000000,0.001); Link link_router_dest=new DuplexLink(64000,0.1); src_iface.attach(link_src_router,true); route_iface192.attach(link_src_router,true); sim.attach(link_src_router); route_iface128.attach(link_router_dest,true); dest_iface.attach(link_router_dest,true); sim.attach(link_router_dest); src.addDefaultRoute(src_iface); dest.addDefaultRoute(dest_iface); router.addRoute(new IPAddr(192,168,1,0),new IPAddr(255,255,255,0), route_iface192); router.addRoute(new IPAddr(128,116,11,0),new IPAddr(255,255,255,0), route_iface128); sim.run(); } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote