Skip to content

Instantly share code, notes, and snippets.

@bign8
Last active February 12, 2017 01:59
Show Gist options
  • Save bign8/07f76938890883545556746c0a5d6bb3 to your computer and use it in GitHub Desktop.
Save bign8/07f76938890883545556746c0a5d6bb3 to your computer and use it in GitHub Desktop.
CSCI-566 Project 1
out
*_m.*
.*
!.gitignore
CSCI_566_proj_1
results

CSCI-566 Project 1

  • Nate Woods
  • Lisa Peters

Compiling

This has only been tested on Mac OSX Sierra

make clean
make
run

Answers

Part A

  1. Install Omnet++ (check)
  2. Go through the tic toc tutorial (check)
  3. Do the exercise in Step 10 of the tic toc tutorial (See QuestionA1)
  4. Do the exercise in Step 13 of the tic toc tutorial (See QuestionA2)
  5. Add random processing delay at each node; Graph delay vs hop count.
    For internal nodes (Indexs 0, 2, 3 and 5)
    Edge Graph Nodes
    For internal nodes (Indexs 1 and 4)
    Internal Graph Nodes

Part B

  1. WIP
/*
* File: lrucache.hpp
* Author: Alexander Ponomarev
* Github: https://github.com/lamerman/cpp-lru-cache
*
* Created on June 20, 2013, 5:09 PM
*/
#ifndef _LRUCACHE_HPP_INCLUDED_
#define _LRUCACHE_HPP_INCLUDED_
#include <unordered_map>
#include <list>
#include <cstddef>
#include <stdexcept>
namespace cache {
template<typename key_t, typename value_t>
class lru_cache {
public:
typedef typename std::pair<key_t, value_t> key_value_pair_t;
typedef typename std::list<key_value_pair_t>::iterator list_iterator_t;
lru_cache(size_t max_size) :
_max_size(max_size) {
}
void put(const key_t& key, const value_t& value) {
auto it = _cache_items_map.find(key);
_cache_items_list.push_front(key_value_pair_t(key, value));
if (it != _cache_items_map.end()) {
_cache_items_list.erase(it->second);
_cache_items_map.erase(it);
}
_cache_items_map[key] = _cache_items_list.begin();
if (_cache_items_map.size() > _max_size) {
auto last = _cache_items_list.end();
last--;
_cache_items_map.erase(last->first);
_cache_items_list.pop_back();
}
}
const value_t& get(const key_t& key) {
auto it = _cache_items_map.find(key);
if (it == _cache_items_map.end()) {
throw std::range_error("There is no such key in cache");
} else {
_cache_items_list.splice(_cache_items_list.begin(), _cache_items_list, it->second);
return it->second->second;
}
}
bool exists(const key_t& key) const {
return _cache_items_map.find(key) != _cache_items_map.end();
}
size_t size() const {
return _cache_items_map.size();
}
private:
std::list<key_value_pair_t> _cache_items_list;
std::unordered_map<key_t, list_iterator_t> _cache_items_map;
size_t _max_size;
};
} // namespace lru
#endif /* _LRUCACHE_HPP_INCLUDED_ */
#
# OMNeT++/OMNEST Makefile for CSCI_566_proj_1
#
# This file was generated with the command:
# opp_makemake -f --deep -O out -I../inet/src -L../inet/out/$$\(CONFIGNAME\)/src -lINET -KINET_PROJ=../inet
#
# Name of target to be created (-o option)
TARGET = CSCI_566_proj_1$(EXE_SUFFIX)
# User interface (uncomment one) (-u option)
USERIF_LIBS = $(ALL_ENV_LIBS) # that is, $(TKENV_LIBS) $(QTENV_LIBS) $(CMDENV_LIBS)
#USERIF_LIBS = $(CMDENV_LIBS)
#USERIF_LIBS = $(TKENV_LIBS)
#USERIF_LIBS = $(QTENV_LIBS)
# C++ include paths (with -I)
INCLUDE_PATH = -I../inet/src -I. -Iresults
# Additional object and library files to link with
EXTRA_OBJS =
# Additional libraries (-L, -l options)
LIBS = -L../inet/out/$(CONFIGNAME)/src -lINET
LIBS += -Wl,-rpath,`abspath ../inet/out/$(CONFIGNAME)/src`
# Output directory
PROJECT_OUTPUT_DIR = out
PROJECTRELATIVE_PATH =
O = $(PROJECT_OUTPUT_DIR)/$(CONFIGNAME)/$(PROJECTRELATIVE_PATH)
# Object files for local .cc, .msg and .sm files
OBJS = $O/QuestionA1.o $O/QuestionA2.o $O/QuestionB.o $O/QuestionA2_m.o
# Message files
MSGFILES = \
QuestionA2.msg
# SM files
SMFILES =
# Other makefile variables (-K)
INET_PROJ=../inet
#------------------------------------------------------------------------------
# Pull in OMNeT++ configuration (Makefile.inc or configuser.vc)
ifneq ("$(OMNETPP_CONFIGFILE)","")
CONFIGFILE = $(OMNETPP_CONFIGFILE)
else
ifneq ("$(OMNETPP_ROOT)","")
CONFIGFILE = $(OMNETPP_ROOT)/Makefile.inc
else
CONFIGFILE = $(shell opp_configfilepath)
endif
endif
ifeq ("$(wildcard $(CONFIGFILE))","")
$(error Config file '$(CONFIGFILE)' does not exist -- add the OMNeT++ bin directory to the path so that opp_configfilepath can be found, or set the OMNETPP_CONFIGFILE variable to point to Makefile.inc)
endif
include $(CONFIGFILE)
# Simulation kernel and user interface libraries
OMNETPP_LIB_SUBDIR = $(OMNETPP_LIB_DIR)/$(TOOLCHAIN_NAME)
OMNETPP_LIBS = -L"$(OMNETPP_LIB_SUBDIR)" -L"$(OMNETPP_LIB_DIR)" -loppmain$D $(USERIF_LIBS) $(KERNEL_LIBS) $(SYS_LIBS)
COPTS = $(CFLAGS) $(INCLUDE_PATH) -I$(OMNETPP_INCL_DIR)
MSGCOPTS = $(INCLUDE_PATH)
SMCOPTS =
# we want to recompile everything if COPTS changes,
# so we store COPTS into $COPTS_FILE and have object
# files depend on it (except when "make depend" was called)
COPTS_FILE = $O/.last-copts
ifneq ($(MAKECMDGOALS),depend)
ifneq ("$(COPTS)","$(shell cat $(COPTS_FILE) 2>/dev/null || echo '')")
$(shell $(MKPATH) "$O" && echo "$(COPTS)" >$(COPTS_FILE))
endif
endif
#------------------------------------------------------------------------------
# User-supplied makefile fragment(s)
# >>>
# <<<
#------------------------------------------------------------------------------
# Main target
all: $O/$(TARGET)
$(Q)$(LN) $O/$(TARGET) .
$O/$(TARGET): $(OBJS) $(wildcard $(EXTRA_OBJS)) Makefile
@$(MKPATH) $O
@echo Creating executable: $@
$(Q)$(CXX) $(LDFLAGS) -o $O/$(TARGET) $(OBJS) $(EXTRA_OBJS) $(AS_NEEDED_OFF) $(WHOLE_ARCHIVE_ON) $(LIBS) $(WHOLE_ARCHIVE_OFF) $(OMNETPP_LIBS)
.PHONY: all clean cleanall depend msgheaders smheaders
.SUFFIXES: .cc
$O/%.o: %.cc $(COPTS_FILE)
@$(MKPATH) $(dir $@)
$(qecho) "$<"
$(Q)$(CXX) -c $(CXXFLAGS) $(COPTS) -o $@ $<
%_m.cc %_m.h: %.msg
$(qecho) MSGC: $<
$(Q)$(MSGC) -s _m.cc $(MSGCOPTS) $?
%_sm.cc %_sm.h: %.sm
$(qecho) SMC: $<
$(Q)$(SMC) -c++ -suffix cc $(SMCOPTS) $?
msgheaders: $(MSGFILES:.msg=_m.h)
smheaders: $(SMFILES:.sm=_sm.h)
clean:
$(qecho) Cleaning...
$(Q)-rm -rf $O
$(Q)-rm -f CSCI_566_proj_1 CSCI_566_proj_1.exe libCSCI_566_proj_1.so libCSCI_566_proj_1.a libCSCI_566_proj_1.dll libCSCI_566_proj_1.dylib
$(Q)-rm -f ./*_m.cc ./*_m.h ./*_sm.cc ./*_sm.h
$(Q)-rm -f results/*_m.cc results/*_m.h results/*_sm.cc results/*_sm.h
cleanall: clean
$(Q)-rm -rf $(PROJECT_OUTPUT_DIR)
depend:
$(qecho) Creating dependencies...
$(Q)$(MAKEDEPEND) $(INCLUDE_PATH) -f Makefile -P\$$O/ -- $(MSG_CC_FILES) $(SM_CC_FILES) ./*.cc results/*.cc
# DO NOT DELETE THIS LINE -- make depend depends on it.
$O/QuestionA1.o: QuestionA1.cc
$O/QuestionA2.o: QuestionA2.cc \
QuestionA2_m.h
$O/QuestionA2_m.o: QuestionA2_m.cc \
QuestionA2_m.h
$O/QuestionB.o: QuestionB.cc \
$(INET_PROJ)/src/inet/applications/httptools/browser/HttpBrowser.h \
$(INET_PROJ)/src/inet/applications/httptools/browser/HttpBrowserBase.h \
$(INET_PROJ)/src/inet/applications/httptools/common/HttpEventMessages_m.h \
$(INET_PROJ)/src/inet/applications/httptools/common/HttpMessages_m.h \
$(INET_PROJ)/src/inet/applications/httptools/common/HttpNodeBase.h \
$(INET_PROJ)/src/inet/applications/httptools/common/HttpRandom.h \
$(INET_PROJ)/src/inet/applications/httptools/common/HttpUtils.h \
$(INET_PROJ)/src/inet/applications/httptools/configurator/HttpController.h \
$(INET_PROJ)/src/inet/applications/httptools/server/HttpServer.h \
$(INET_PROJ)/src/inet/applications/httptools/server/HttpServerBase.h \
$(INET_PROJ)/src/inet/common/Compat.h \
$(INET_PROJ)/src/inet/common/INETDefs.h \
$(INET_PROJ)/src/inet/common/INETMath.h \
$(INET_PROJ)/src/inet/common/InitStages.h \
$(INET_PROJ)/src/inet/common/NotifierConsts.h \
$(INET_PROJ)/src/inet/common/lifecycle/ILifecycle.h \
$(INET_PROJ)/src/inet/common/lifecycle/LifecycleOperation.h \
$(INET_PROJ)/src/inet/features.h \
$(INET_PROJ)/src/inet/linklayer/common/MACAddress.h \
$(INET_PROJ)/src/inet/networklayer/common/InterfaceEntry.h \
$(INET_PROJ)/src/inet/networklayer/common/InterfaceToken.h \
$(INET_PROJ)/src/inet/networklayer/common/L3Address.h \
$(INET_PROJ)/src/inet/networklayer/common/L3AddressResolver.h \
$(INET_PROJ)/src/inet/networklayer/common/ModuleIdAddress.h \
$(INET_PROJ)/src/inet/networklayer/common/ModulePathAddress.h \
$(INET_PROJ)/src/inet/networklayer/contract/IRoute.h \
$(INET_PROJ)/src/inet/networklayer/contract/IRoutingTable.h \
$(INET_PROJ)/src/inet/networklayer/contract/ipv4/IPv4Address.h \
$(INET_PROJ)/src/inet/networklayer/contract/ipv6/IPv6Address.h \
$(INET_PROJ)/src/inet/transportlayer/contract/tcp/TCPCommand_m.h \
$(INET_PROJ)/src/inet/transportlayer/contract/tcp/TCPSocket.h \
$(INET_PROJ)/src/inet/transportlayer/contract/tcp/TCPSocketMap.h
[General]
# nothing here
[Config QuestionA1]
network = QuestionA1
[Config QuestionA2]
network = QuestionA2
QuestionA2.tic[*].delayTime = exponential(3s) # Exercise 13 (Question 4)
[Config QuestionB]
network = QuestionB
# Controller
*.controller.config = xmldoc("QuestionB.xml","//controller-profile[@id='uniform']")
*.controller.events = "QuestionB.cfg"
*.controller.eventsSection = "default"
# udp app (off)
**.numUdpApps = 0
# Origin
*.origin.numTcpApps = 1
*.origin.tcpApp[0].typename = "HttpServer"
*.origin.tcpApp[0].hostName = "origin.example.org"
*.origin.tcpApp[0].config = xmldoc("QuestionB.xml","//server-profile[@id='normal']")
*.origin.tcpApp[0].port = 80
*.origin.tcpApp[0].activationTime = 0.0
# CDNServer
*.server*.numTcpApps = 2
*.server*.tcpApp[0].typename = "CDNServer"
*.server1.tcpApp[0].hostName = "cdn1.example.org"
*.server2.tcpApp[0].hostName = "cdn2.example.org"
*.server*.tcpApp[0].config = xmldoc("QuestionB.xml","//server-profile[@id='normal']")
*.server*.tcpApp[0].port = 80
*.server*.tcpApp[0].activationTime = 0.0
# CDNBrowser
*.server*.tcpApp[1].typename = "CDNBrowser"
*.server*.tcpApp[1].config = xmldoc("QuestionB.xml","//user-profile[@id='normal']")
*.server*.tcpApp[1].activationTime = 0.0
*.server*.tcpApp[1].scriptFile = "QuestionB.script"
# Clients
*.client[*].numTcpApps = 1
*.client[*].tcpApp[0].typename = "StatsBrowser"
*.client[*].tcpApp[0].logFile = "results/clients.log"
*.client[*].tcpApp[0].config = xmldoc("QuestionB.xml","//user-profile[@id='normal']")
*.client[*].tcpApp[0].activationTime = 0.0
package csci_566_proj_1;
@license(LGPL);
#include <stdio.h>
#include <string.h>
#include <omnetpp.h>
using namespace omnetpp;
class TxcA1 : public cSimpleModule {
protected:
virtual void forwardMessage(cMessage *msg);
virtual void initialize() override;
virtual void handleMessage(cMessage *msg) override;
};
Define_Module(TxcA1);
void TxcA1::initialize() {
if (getIndex() == 0) {
char msgname[20];
sprintf(msgname, "tic-%d", getIndex());
cMessage *msg = new cMessage(msgname);
scheduleAt(0.0, msg);
}
}
void TxcA1::handleMessage(cMessage *msg) {
if (getIndex() == 3) {
EV << "Message " << msg << " arrived.\n";
delete msg;
} else {
forwardMessage(msg);
}
}
void TxcA1::forwardMessage(cMessage *msg) {
int n = gateSize("port");
// START: Exercise 10 (Question 3) If randomly generated number is same as input gate, generate again
cGate *arrival = msg->getArrivalGate();
int k;
do {
k = intuniform(0, n-1);
} while (arrival != nullptr && n > 1 && k == arrival->getIndex());
// STOP: Exercise 10 (Question 3)
EV << "Forwarding message " << msg << " on port out[" << k << "]\n";
send(msg, "port$o", k);
}
package csci_566_proj_1;
simple TxcA1 {
parameters:
volatile double delayTime @unit(s); // Exercise 13 (Question 4)
@display("i=block/routing");
gates:
inout port[];
}
network QuestionA1 {
types:
channel Channel extends ned.DelayChannel { delay = 100ms; }
submodules:
tic[6]: TxcA1;
connections:
tic[0].port++ <--> Channel <--> tic[1].port++;
tic[1].port++ <--> Channel <--> tic[2].port++;
tic[1].port++ <--> Channel <--> tic[4].port++;
tic[3].port++ <--> Channel <--> tic[4].port++;
tic[4].port++ <--> Channel <--> tic[5].port++;
}
#include <stdio.h>
#include <string.h>
#include <omnetpp.h>
using namespace omnetpp;
#include "QuestionA2_m.h"
class TxcA2 : public cSimpleModule {
protected:
virtual QuestionA2Msg *generateMessage();
virtual void forwardMessage(QuestionA2Msg *msg);
virtual void initialize() override;
virtual void handleMessage(cMessage *msg) override;
};
Define_Module(TxcA2);
void TxcA2::initialize() {
QuestionA2Msg *msg = generateMessage();
if (getIndex() == 0) {
scheduleAt(0.0, msg);
} else {
scheduleAt(par("delayTime"), msg);
}
}
void TxcA2::handleMessage(cMessage *msg) {
// If message is ours, schedule another one to come down the pipe later
if (msg->isSelfMessage()) {
EV << "Enquing another message: ";
QuestionA2Msg *newmsg = generateMessage();
EV << newmsg << endl;
scheduleAt(simTime() + par("delayTime"), newmsg);
}
QuestionA2Msg *ttmsg = check_and_cast<QuestionA2Msg *>(msg);
if (ttmsg->getDestination() == getIndex()) {
// Message arrived.
EV << "Message " << ttmsg << " arrived after " << ttmsg->getHopCount() << " hops.\n";
bubble("ARRIVED, starting new one!");
delete ttmsg;
} else {
// We need to forward the message.
forwardMessage(ttmsg);
}
}
QuestionA2Msg *TxcA2::generateMessage() {
// Produce source and destination addresses.
int src = getIndex(); // our module index
int n = getVectorSize(); // module vector size
int dest = intuniform(0, n-2);
if (dest >= src)
dest++;
char msgname[20];
sprintf(msgname, "tic-%d-to-%d", src, dest);
// Create message object and set source and destination field.
QuestionA2Msg *msg = new QuestionA2Msg(msgname);
msg->setSource(src);
msg->setDestination(dest);
return msg;
}
void TxcA2::forwardMessage(QuestionA2Msg *msg) {
msg->setHopCount(msg->getHopCount()+1);
// Same routing as before: random gate.
int n = gateSize("gate");
int k = intuniform(0, n-1);
EV << "Forwarding message " << msg << " on gate[" << k << "]\n";
send(msg, "gate$o", k);
}
message QuestionA2Msg {
int source;
int destination;
int hopCount = 0;
}
package csci_566_proj_1;
simple TxcA2 {
parameters:
volatile double delayTime @unit(s); // delay before transmitting a new message
@display("i=block/routing");
gates:
inout gate[];
}
network QuestionA2 {
types:
channel Channel extends ned.DelayChannel { delay = 100ms; }
submodules:
tic[6]: TxcA2;
connections:
tic[0].gate++ <--> Channel <--> tic[1].gate++;
tic[1].gate++ <--> Channel <--> tic[2].gate++;
tic[1].gate++ <--> Channel <--> tic[4].gate++;
tic[3].gate++ <--> Channel <--> tic[4].gate++;
tic[4].gate++ <--> Channel <--> tic[5].gate++;
}
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#include <unordered_map>
#include <omnetpp.h>
#include "inet/applications/httptools/server/HttpServer.h"
#include "inet/applications/httptools/browser/HttpBrowser.h"
#include "lru_h.hpp"
namespace omnetpp {
/*
* Modified for debugging!
* - HttpServerBase.cc::updateDisplay()
* Modified sprintf to be as follows:
* sprintf(buf, "htm: %ld, img: %ld, txt: %ld", htmlDocsServed, imgResourcesServed, textResourcesServed);
*/
/*
* CDNBrowser Implementation
*/
class CDNBrowser : public inet::httptools::HttpBrowser {
public:
virtual void handleMessage(cMessage *msg) override;
virtual void socketDataArrived(int connId, void *yourPtr, cPacket *msg, bool urgent) override;
};
void CDNBrowser::handleMessage(cMessage *msg) {
inet::httptools::HttpRequestMessage *msg2 = dynamic_cast<inet::httptools::HttpRequestMessage *>(msg);
if (msg2 == nullptr) {
inet::httptools::HttpBrowser::handleMessage(msg);
} else {
this->sendRequestToServer(msg2);
}
}
void CDNBrowser::socketDataArrived(int connId, void *yourPtr, cPacket *msg, bool urgent) {
if (yourPtr == nullptr) { EV_ERROR << "socketDataArrivedfailure. Null pointer" << endl; return; }
EV_DEBUG << "CDNBrowser: Socket data arrived on connection " << connId << ": " << msg->getName() << endl;
SockData *sockdata = (SockData *)yourPtr;
inet::TCPSocket *socket = sockdata->socket;
// Send client data to consumer
this->sendDirect(msg, this->getParentModule()->getSubmodule("tcpApp", 0), 0);
if (--sockdata->pending == 0) {
EV_DEBUG << "Received last expected reply on this socket. Issuing a close" << endl;
socket->close();
}
// Message deleted in handler - do not delete here!
}
/*
* CDNServer Implementation
*/
class CDNServer : public inet::httptools::HttpServer {
public:
CDNServer();
~CDNServer();
protected:
struct Remember {
inet::TCPSocket *sock;
std::string slug;
int serial;
};
std::map<int, Remember> sockMap;
cache::lru_cache<std::string, std::string> lru;
virtual void socketDataArrived(int connId, void *yourPtr, cPacket *msg, bool urgent) override;
virtual void handleMessage(cMessage *msg) override;
};
CDNServer::CDNServer() : lru(2) {}; // TODO: parse 2 from model parameters
CDNServer::~CDNServer() {
// This is crashing when closing the Simulation
// for (auto & elem : sockMap) delete elem.second;
// sockMap.clear();
};
void CDNServer::handleMessage(cMessage *msg) {
inet::httptools::HttpReplyMessage *msg2 = dynamic_cast<inet::httptools::HttpReplyMessage *>(msg);
if (msg2 == nullptr) {
inet::httptools::HttpServer::handleMessage(msg);
} else {
Remember memory = sockMap.find(msg2->serial())->second;
EV_INFO << "FOUND SOCKET!!!" << msg2->serial() << " " << memory.sock->getState() << endl;
inet::httptools::HttpReplyMessage *res = new inet::httptools::HttpReplyMessage(*msg2);
res->setOriginatorUrl(hostName.c_str());
res->setSerial(memory.serial);
EV_INFO << "CDNServer: Returning Content 1 '" << msg2->targetUrl() << "' '" << msg2->originatorUrl() << "'" << msg2->heading() << endl;
EV_INFO << "CDNServer: Returning Content 2 '" << res->targetUrl() << "' '" << res->originatorUrl() << "'" << endl;
memory.sock->send(res);
lru.put(memory.slug, msg2->payload());
EV_INFO << "CDNServer: Caching Resource" << memory.slug << endl;
delete msg;
}
};
void CDNServer::socketDataArrived(int connId, void *yourPtr, cPacket *msg, bool urgent) {
if (yourPtr == nullptr) { EV_ERROR << "Socket establish failure. Null pointer" << endl; return; }
EV_DEBUG << "CDNServer: Socket data arrived on connection " << connId << ". Message=" << msg->getName() << ", kind=" << msg->getKind() << endl;
inet::TCPSocket *socket = (inet::TCPSocket *)yourPtr;
// Process message
inet::httptools::HttpRequestMessage *request = check_and_cast<inet::httptools::HttpRequestMessage *>(msg);
std::string resource = cStringTokenizer(request->heading(), " ").asVector()[1];
// Search Cache
if (!lru.exists(resource)) {
// Create Origin Lookup Request
inet::httptools::HttpRequestMessage *newRequest = new inet::httptools::HttpRequestMessage(*request);
newRequest->setTargetUrl("origin.example.org");
newRequest->setSerial(socket->getConnectionId());
EV_INFO << "CDNServer: Requesting Content 1'" << request->targetUrl() << "' '" << request->originatorUrl() << "'"<< request->heading() << endl;
EV_INFO << "CDNServer: Requesting Content 2'" << newRequest->targetUrl() << "' '" << newRequest->originatorUrl() << "'" << request->heading() << endl;
this->sendDirect(newRequest, this->getParentModule()->getSubmodule("tcpApp", 1), 0);
sockMap[connId].sock = socket;
sockMap[connId].slug = resource;
sockMap[connId].serial = request->serial();
} else {
// Directly respond
EV_INFO << "CDNServer: Found Resource " << resource << endl;
char szReply[512];
sprintf(szReply, "HTTP/1.1 200 OK (%s)", resource.c_str());
inet::httptools::HttpReplyMessage *replymsg = new inet::httptools::HttpReplyMessage(szReply);
replymsg->setHeading("HTTP/1.1 200 OK");
replymsg->setOriginatorUrl(hostName.c_str());
replymsg->setTargetUrl(request->originatorUrl());
replymsg->setProtocol(request->protocol());
replymsg->setSerial(request->serial());
replymsg->setResult(200);
replymsg->setContentType(inet::httptools::CT_HTML); // Emulates the content-type header field
replymsg->setKind(HTTPT_RESPONSE_MESSAGE);
std::string body = lru.get(resource);
replymsg->setPayload(body.c_str());
replymsg->setByteLength(body.length());
socket->send(replymsg);
}
// Update service stats
switch (inet::httptools::getResourceCategory(inet::httptools::parseResourceName(resource))) {
case inet::httptools::CT_HTML: htmlDocsServed++; break;
case inet::httptools::CT_TEXT: textResourcesServed++; break;
case inet::httptools::CT_IMAGE: imgResourcesServed++; break;
default: EV_WARN << "CDNServer: Received Unknown request type: " << resource << endl; break;
};
delete msg; // Delete the received message here. Must not be deleted in the handler!
};
/*
* StatsBrowser Implementation
*/
class StatsBrowser : public inet::httptools::HttpBrowser {
protected:
static simsignal_t rcvdPkSignal;
// virtual void handleDataMessage(cMessage *msg) override;
};
simsignal_t StatsBrowser::rcvdPkSignal = registerSignal("rcvdPk");
//void StatsBrowser::handleDataMessage(cMessage *msg) {
// EV << "NATE!!!" << endl;
// inet::httptools::HttpBrowser::handleDataMessage(msg);
//};
// emit(rcvdPkSignal, msg);
Define_Module(CDNServer);
Define_Module(CDNBrowser);
Define_Module(StatsBrowser);
};
# Format: {time};{www name};{event kind};{p value};{amortization factor}
# Event kind is not used at the present -- use 1 as a default value.
[default]
0;cdn1.example.org;1;0.5;0
0;cdn2.example.org;1;0.5;0
0;origin.example.org;1;0;0
package csci_566_proj_1;
import inet.applications.httptools.configurator.HttpController;
import inet.networklayer.configurator.ipv4.IPv4NetworkConfigurator;
import inet.node.inet.Router;
import inet.node.inet.StandardHost;
import inet.applications.contract.ITCPApp;
import inet.applications.httptools.browser.HttpBrowser;
channel ethernetline extends ned.DatarateChannel {
parameters:
delay = 0.1us;
datarate = 100Mbps;
}
simple CDNServer like ITCPApp {
parameters:
string hostName = default(""); // The domain name of the server
int port = default(80); // The listening port number
int httpProtocol = default(11); // The http protocol: 10 for http/1.0, 11 for http/1.1. Not used at the present time.
string logFile = default(""); // Name of server log file. Events are appended, allowing sharing of file for multiple servers.
string siteDefinition = default(""); // The site script file. Blank to disable.
double activationTime @unit("s") = default(0s); // The initial activation delay. Zero to disable.
xml config; // The XML configuration file for random sites
gates:
input responses @directIn; // CDNBrowser calls back into this
input tcpIn;
output tcpOut;
}
simple CDNBrowser like ITCPApp {
parameters:
int httpProtocol = default(11); // The http protocol: 10 for http/1.0, 11 for http/1.1. Not used at the present time.
string logFile = default(""); // Name of a browser log file. Browse events are appended, allowing sharing of file for multiple browsers.
string scriptFile = default(""); // The browsing script file. Blank to disable.
double activationTime @unit("s") = default(0s); // The initial activation delay. Zero to disable. This is the time at which the browser first comes to life in a simulation scenario. Note that this can be any random distribution which OMNeT++ supports.
xml config; // The XML config file
string httpBrowserControllerModule = default("controller"); // the absolute path to the http browser controller, @see HttpController
gates:
input requests @directIn; // CDNServer makes requests into here
input tcpIn;
output tcpOut;
}
simple StatsBrowser extends HttpBrowser {
parameters:
@signal[rcvdPk](type=cPacket);
@statistic[endToEndDelay](title="end-to-end delay"; source="messageAge(rcvdPk)"; unit=s; record=histogram,vector; interpolationmode=none);
}
network QuestionB {
parameters:
double numclients @prompt("Number of clients") = default(1);
@display("bgb=1000,600;bgl=4");
submodules:
configurator: IPv4NetworkConfigurator {
parameters:
@display("p=50,50;i=block/cogwheel");
}
controller: HttpController {
parameters:
@display("p=100,50;i=block/cogwheel");
}
origin: StandardHost {
parameters:
@display("i=device/server_l;p=950,50");
}
router_3: Router {
parameters:
@display("i=abstract/router_l;p=500,50");
}
server1: StandardHost {
parameters:
@display("i=device/server_l;p=950,300");
}
server2: StandardHost {
parameters:
@display("i=device/server_l;p=50,300");
}
router_2: Router {
parameters:
@display("i=abstract/router_l;p=500,300");
}
router_1: Router {
parameters:
@display("i=abstract/router_l;p=500,550");
}
client[numclients]: StandardHost {
parameters:
@display("i=device/laptop_l;p=950,550");
}
connections:
router_1.ethg++ <--> ethernetline <--> router_2.ethg++;
router_2.ethg++ <--> ethernetline <--> router_3.ethg++;
origin.ethg++ <--> ethernetline <--> router_3.ethg++;
server1.ethg++ <--> ethernetline <--> router_2.ethg++;
server2.ethg++ <--> ethernetline <--> router_2.ethg++;
for i=0..numclients-1 {
client[i].ethg++ <--> ethernetline <--> router_1.ethg++;
}
}
0;origin.example.org
<?xml version="1.0" encoding="UTF-8"?>
<root>
<user-profile id="normal">
<activityPeriod type='normal' mean='28800' sd='10800' min='7200' />
<interRequestInterval type='normal' mean='600' sd='60' nonNegative='true' min='60.0' />
<interSessionInterval type='normal' mean='3600' sd='1800' nonNegative='true' min='120.0' />
<requestSize type='normal' mean='600' sd='100' nonNegative='true' min='300' />
<reqInSession type='normal' mean='10' sd='5' nonNegative='true' min='2' />
<processingDelay type='normal' mean='0.05' sd='0.01' nonNegative='true' />
</user-profile>
<server-profile id="normal">
<htmlPageSize type='exponential' mean='2000' min='1000' />
<replyDelay type='normal' mean='0.05' sd='0.01' nonNegative='true' min='0.01' />
<textResourceSize type='exponential' mean='10000' min='1000' max='100000' />
<imageResourceSize type='exponential' mean='20000' min='1000' max='500000' />
<numResources type='uniform' beginning='0' end='20' />
<textImageResourceRatio type='uniform' beginning='0.2' end='0.8' />
<errorMessageSize type="constant" value="1024" />
</server-profile>
<controller-profile id="uniform">
<serverPopularityDistribution type='uniform' beginning="0" end="" />
</controller-profile>
</root>
#! /bin/bash
set -e # fail whole thing
set -o pipefail # fail pipes
echo "Building local package"
make CONFIGNAME=gcc-debug
echo "Building inet package"
pushd ../inet/src > /dev/null
make CONFIGNAME=gcc-debug all
popd > /dev/null
echo "Starting simulation"
CSCI_566_proj_1 -c QuestionB -n .:../inet/src -l ../inet/src/INET | sed '/Could not load image/d'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment