Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "src/ui-lovable"]
path = src/ui-lovable
url = https://github.com/anirudhiitj/sim-architect-design.git
18 changes: 18 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"configurations": [
{
"name": "windows-gcc-x86",
"includePath": [
"${workspaceFolder}/**"
],
"compilerPath": "C:/MinGW/bin/gcc.exe",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "windows-gcc-x86",
"compilerArgs": [
""
]
}
],
"version": 4
}
24 changes: 24 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"externalConsole": true,
"cwd": "c:/Users/Admin/Desktop/simrun/src/compiler/validator",
"program": "c:/Users/Admin/Desktop/simrun/src/compiler/validator/build/Debug/outDebug",
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
59 changes: 59 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"C_Cpp_Runner.cCompilerPath": "gcc",
"C_Cpp_Runner.cppCompilerPath": "g++",
"C_Cpp_Runner.debuggerPath": "gdb",
"C_Cpp_Runner.cStandard": "",
"C_Cpp_Runner.cppStandard": "",
"C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/VR_NR/Community/VC/Auxiliary/Build/vcvarsall.bat",
"C_Cpp_Runner.useMsvc": false,
"C_Cpp_Runner.warnings": [
"-Wall",
"-Wextra",
"-Wpedantic",
"-Wshadow",
"-Wformat=2",
"-Wcast-align",
"-Wconversion",
"-Wsign-conversion",
"-Wnull-dereference"
],
"C_Cpp_Runner.msvcWarnings": [
"/W4",
"/permissive-",
"/w14242",
"/w14287",
"/w14296",
"/w14311",
"/w14826",
"/w44062",
"/w44242",
"/w14905",
"/w14906",
"/w14263",
"/w44265",
"/w14928"
],
"C_Cpp_Runner.enableWarnings": true,
"C_Cpp_Runner.warningsAsError": false,
"C_Cpp_Runner.compilerArgs": [],
"C_Cpp_Runner.linkerArgs": [],
"C_Cpp_Runner.includePaths": [],
"C_Cpp_Runner.includeSearch": [
"*",
"**/*"
],
"C_Cpp_Runner.excludeSearch": [
"**/build",
"**/build/**",
"**/.*",
"**/.*/**",
"**/.vscode",
"**/.vscode/**"
],
"C_Cpp_Runner.useAddressSanitizer": false,
"C_Cpp_Runner.useUndefinedSanitizer": false,
"C_Cpp_Runner.useLeakSanitizer": false,
"C_Cpp_Runner.showCompilationTime": false,
"C_Cpp_Runner.useLinkTimeOptimization": false,
"C_Cpp_Runner.msvcSecureNoWarnings": false
}
4 changes: 4 additions & 0 deletions src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
electron/node_modules/
ui/node_modules/
ui-lovable/node_modules/

Empty file removed src/sim/core/.gitkeep
Empty file.
13 changes: 13 additions & 0 deletions src/sim/core/base_entity.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once
#include <string>

class BaseEntity {
public:
explicit BaseEntity(std::string id_) : entity_id(std::move(id_)) {}
virtual ~BaseEntity() = default;

const std::string& id() const { return entity_id; }

private:
std::string entity_id;
};
49 changes: 49 additions & 0 deletions src/sim/core/event_queue.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//event_queue.cpp defines different priority/calender/ladder (for now just pq) queues
//at runtime EventQueue reference may point to any of them (depending on configuration)
#include "event_queue.h"
#include "../events/event.h"
#include <queue>
#include <vector>

using std::unique_ptr;
using std::priority_queue;
using std::vector;
using std::move;

namespace {

struct EventCompare {
bool operator()(
const unique_ptr<Event>& a,
const unique_ptr<Event>& b
) const {
return a->time > b->time;
}
};

class PriorityEventQueue : public EventQueue {
private:
priority_queue<
unique_ptr<Event>,
vector<unique_ptr<Event>>,
EventCompare
> pq;

public:
void push(unique_ptr<Event> e) override {
pq.push(move(e));
}

unique_ptr<Event> pop() override {
auto e = move(pq.top());
pq.pop();
return e;
}

bool empty() const override {
return pq.empty();
}
};

}

14 changes: 14 additions & 0 deletions src/sim/core/event_queue.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//event_queue.h defines the abstract event queue API which will be used by event scheduler
#pragma once
#include <memory>

class Event;

class EventQueue {
public:
virtual ~EventQueue() = default;

virtual void push(std::unique_ptr<Event> e) = 0;
virtual std::unique_ptr<Event> pop() = 0;
virtual bool empty() const = 0;
};
18 changes: 18 additions & 0 deletions src/sim/core/scheduler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once
#include <memory>

class Event;
class EventQueue;

class EventScheduler {
private:
EventQueue& queue; //private as components only schedule the events using scheduler, so they should not be able to inspect it

public:
explicit EventScheduler(EventQueue& q) : queue(q) {}

void schedule(std::unique_ptr<Event> e) {
queue.push(std::move(e));
}

};
5 changes: 5 additions & 0 deletions src/sim/core/sim_types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//this is just for defining alias for uint64_t everywhere
#pragma once
#include <cstdint>

using SimTime = uint64_t;
27 changes: 27 additions & 0 deletions src/sim/core/simulator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "simulator.h"
#include "event_queue.h"
#include "../events/event.h"

Simulator::Simulator(
EventQueue& q,
const Context& ctx,
State& st
)
: queue(q),
scheduler(q),
context(ctx),
state(st) {}

void Simulator::run() {
while (!queue.empty()) {
auto event = queue.pop();

current_time = event->time;

event->execute(context, state, scheduler);
}
}

SimTime Simulator::now() const {
return current_time;
}
33 changes: 33 additions & 0 deletions src/sim/core/simulator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#pragma once
#include "sim_types.h"
#include "scheduler.h"
#include "event_loop.h"

#include "../entities/entity_context.h"
#include "../entities/entity_state.h"

using Context = SimulationContext;
using State = SimulationState;

class EventQueue;

class Simulator final : public EventLoop {
private:
SimTime current_time = 0;

EventQueue& queue;
EventScheduler scheduler;

const Context& context;
State& state;

public:
Simulator(
EventQueue& q,
const Context& ctx,
State& st
);

void run() override;
SimTime now() const;
};
25 changes: 25 additions & 0 deletions src/sim/entities/database.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once
#include "../core/base_entity.h"

class DatabaseEntity final : public BaseEntity {
public:
// ---- context ----
const int capacity;
const double latency_mean;
const double failure_prob;

// ---- state ----
bool is_down = false;
int active_connections = 0;

DatabaseEntity(
std::string id,
int capacity,
double latency_mean,
double failure_prob
)
: BaseEntity(std::move(id)),
capacity(capacity),
latency_mean(latency_mean),
failure_prob(failure_prob) {}
};
29 changes: 29 additions & 0 deletions src/sim/entities/networklink.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once
#include "../core/base_entity.h"
#include <string>

class NetworkLinkEntity final : public BaseEntity {
public:
// ---- context ----
const std::string from;
const std::string to;
const double latency_mean;
const double failure_prob;

// ---- state ----
bool is_down = false;
int in_flight = 0;

NetworkLinkEntity(
std::string id,
std::string from,
std::string to,
double latency_mean,
double failure_prob
)
: BaseEntity(std::move(id)),
from(std::move(from)),
to(std::move(to)),
latency_mean(latency_mean),
failure_prob(failure_prob) {}
};
26 changes: 26 additions & 0 deletions src/sim/entities/service.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once
#include "../core/base_entity.h"

class ServiceEntity final : public BaseEntity {
public:
// ---- context (immutable) ----
const int capacity;
const double latency_mean;
const double failure_prob;

// ---- state (mutable) ----
bool is_down = false;
int active_requests = 0;
int queued_requests = 0;

ServiceEntity(
std::string id,
int capacity,
double latency_mean,
double failure_prob
)
: BaseEntity(std::move(id)),
capacity(capacity),
latency_mean(latency_mean),
failure_prob(failure_prob) {}
};
Loading