Skip to content

Commit

Permalink
Generated from commit d9161f2d0f58197fb6d7a30f2ad0c25163edbc8d
Browse files Browse the repository at this point in the history
  • Loading branch information
Pusnow committed May 14, 2024
1 parent 019960d commit 6170186
Show file tree
Hide file tree
Showing 23 changed files with 11,857 additions and 110 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.11)

project(e VERSION 3.3.3)
project(e VERSION 3.3.6)

# Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24:
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
Expand Down
5 changes: 5 additions & 0 deletions Documentation/etc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# ETC Documentation

| Title | Links |
|-------------------------------|-------------------------------------------------------------------------------------------------|
| Pee-Wee OSPF Protocol Details | [Doc](pwospf.txt), [Source](https://www.cl.cam.ac.uk/teaching/1011/P33/documentation/pwospf/) |
430 changes: 430 additions & 0 deletions Documentation/etc/pwospf.txt

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Documentation/rfc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
|----------|-------------------------------|-------------------------------------------------------------------------|
| RFC 791 | INTERNET PROTOCOL | [Doc](rfc791.txt), [Errata](https://www.rfc-editor.org/errata/rfc791) |
| RFC 793 | TRANSMISSION CONTROL PROTOCOL | [Doc](rfc793.txt), [Errata](https://www.rfc-editor.org/errata/rfc793) |
| RFC 1247 | OSPF Version 2 | [Doc](rfc1247.txt), [Errata](https://www.rfc-editor.org/errata/rfc1247) |
| RFC 5681 | TCP Congestion Control | [Doc](rfc5681.txt), [Errata](https://www.rfc-editor.org/errata/rfc5681) |
10,585 changes: 10,585 additions & 0 deletions Documentation/rfc/rfc1247.txt

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions app/kens/testenv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,8 @@ class TestEnv3 : public KensTesting {
}
};

//#define UNRELIABLE
//#define RUN_SOLUTION
// #define UNRELIABLE
// #define RUN_SOLUTION
#ifdef RUN_SOLUTION
typedef TestEnv1<TCPSolutionProvider> TestEnv_Reliable;
#ifdef UNRELIABLE
Expand Down
26 changes: 26 additions & 0 deletions app/pwospf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
project(pwospf)

# Build pwospf

set(pwospf_SOURCES PWOSPFAssignment.cpp PWOSPFAssignment.hpp)
add_library(pwospf SHARED ${pwospf_SOURCES})
target_link_libraries(pwospf PUBLIC e)

set(pwospf-targets pwospf)

if(TARGET pwospf-ref)
list(APPEND pwospf-targets pwospf-ref)
endif()

foreach(pwospf-traget ${pwospf-targets})
add_executable(${pwospf-traget}-all testpwospf.cpp)
target_link_libraries(${pwospf-traget}-all PUBLIC ${pwospf-traget} gtest_main)
if(${CMAKE_VERSION} VERSION_GREATER "3.15.0")
set_target_properties(${pwospf-traget}-all PROPERTIES XCODE_GENERATE_SCHEME
ON)
set_target_properties(${pwospf-traget}-all PROPERTIES XCODE_SCHEME_ARGUMENTS
"--gtest_color=no")
set_target_properties(${pwospf-traget}-all
PROPERTIES XCODE_SCHEME_ENVIRONMENT "GTEST_COLOR=no")
endif()
endforeach()
50 changes: 50 additions & 0 deletions app/pwospf/PWOSPFAssignment.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* E_PWOSPFAssignment.cpp
*
*/

#include <E/E_Common.hpp>
#include <E/Networking/E_Host.hpp>
#include <E/Networking/E_NetworkUtil.hpp>
#include <E/Networking/E_Networking.hpp>
#include <E/Networking/E_Packet.hpp>
#include <cerrno>

#include "PWOSPFAssignment.hpp"

namespace E {

PWOSPFAssignment::PWOSPFAssignment(Host &host)
: HostModule("OSPF", host), RoutingInfoInterface(host),
TimerModule("OSPF", host) {}

PWOSPFAssignment::~PWOSPFAssignment() {}

void PWOSPFAssignment::initialize() {}

void PWOSPFAssignment::finalize() {}

/**
* @brief Query cost for a host
*
* @param ipv4 querying host's IP address
* @return cost or -1 for no found host
*/
Size PWOSPFAssignment::pwospfQuery(const ipv4_t &ipv4) {
// Implement below

return -1;
}

void PWOSPFAssignment::packetArrived(std::string fromModule, Packet &&packet) {
// Remove below
(void)fromModule;
(void)packet;
}

void PWOSPFAssignment::timerCallback(std::any payload) {
// Remove below
(void)payload;
}

} // namespace E
140 changes: 140 additions & 0 deletions app/pwospf/PWOSPFAssignment.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/*
* E_PWOSPFAssignment.hpp
*
*/

#ifndef E_PWOSPFASSIGNMENT_HPP_
#define E_PWOSPFASSIGNMENT_HPP_

#include <E/E_TimeUtil.hpp>
#include <E/Networking/E_Host.hpp>
#include <E/Networking/E_Networking.hpp>
#include <E/Networking/E_TimerModule.hpp>
#include <E/Networking/E_Wire.hpp>

namespace E {

constexpr Size MaxCost = 20;
constexpr Size calc_cost_lcm(size_t a) {
return a == 1 ? 1 : std::lcm(a, calc_cost_lcm(a - 1));
}
constexpr Size CostLCM = calc_cost_lcm(MaxCost);

/* Router Configuration */

// 32 bit area ID
constexpr uint32_t AreaID = 1;
// 16 bit lsuint - interval in seconds between link state update broadcasts
constexpr uint16_t LSUInt = 30;
constexpr uint16_t TTLInitial = 16;

// 32 bit mask mask - subnet mask of assocaited interface
constexpr ipv4_t SubnetMask = {255, 255, 255, 0};

// 16 bit helloint - interval in seconds between HELLO broadcasts
constexpr uint16_t HelloInt = 60;

/* Router Configuration End*/

#ifdef HAVE_PRAGMA_PACK
#pragma pack(push, 1)
#elif !defined(HAVE_ATTR_PACK)
#error "Compiler must support packing"
#endif

struct pwospf_header_t {
uint8_t version;
uint8_t type;
uint16_t length;
uint32_t router_id;
uint32_t area_id;
uint16_t checksum;
uint16_t authtype;
uint64_t authentication;
}
#if defined(HAVE_ATTR_PACK)
__attribute__((packed));
#else
;
#endif

struct pwospf_hello_t {
struct pwospf_header_t header;
uint32_t network_mask;
uint16_t hello_int;
uint16_t padding;
}
#if defined(HAVE_ATTR_PACK)
__attribute__((packed));
#else
;
#endif

struct pwospf_lsu_entry_t {
uint32_t subnet;
uint32_t mask;
uint32_t router_id;
uint32_t cost;
}
#if defined(HAVE_ATTR_PACK)
__attribute__((packed));
#else
;
#endif

struct pwospf_lsu_t {
struct pwospf_header_t header;
uint16_t sequence;
uint16_t ttl;
uint32_t num_advertisements;
struct pwospf_lsu_entry_t entries[];
}
#if defined(HAVE_ATTR_PACK)
__attribute__((packed));
#else
;
#endif

class PWOSPFAssignment : public HostModule,
private RoutingInfoInterface,
public TimerModule {
private:
virtual void timerCallback(std::any payload) final;

public:
PWOSPFAssignment(Host &host);

/**
* @brief Query cost for a host
*
* @param ipv4 querying host's IP address
* @return cost or -1 for no found host
*/
Size pwospfQuery(const ipv4_t &ipv4);

/**
* @brief Get cost for local port (link)
*
* @param port_num querying port's number
* @return local link cost
*/
Size linkCost(int port_num) {
Size bps = this->getWireSpeed(port_num);
return CostLCM / bps;
}

virtual void initialize();
virtual void finalize();
virtual ~PWOSPFAssignment();

protected:
virtual std::any diagnose(std::any param) final {
auto ip = std::any_cast<ipv4_t>(param);
return pwospfQuery(ip);
}
virtual void packetArrived(std::string fromModule, Packet &&packet) final;
};

} // namespace E

#endif /* E_PWOSPFASSIGNMENT_HPP_ */
80 changes: 80 additions & 0 deletions app/pwospf/pwospf.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
p_pwospf = Proto("pwospf", "PWOSPF")
local f = p_pwospf.fields
f.ver = ProtoField.uint8("pwospf.ver", "Version", base.DEC)
f.tp = ProtoField.uint8("pwospf.tp", "Type", base.DEC)
f.length = ProtoField.uint16("pwospf.length", "Packet length", base.DEC)
f.routerid = ProtoField.ipv4("pwospf.routerid", "Router ID")
f.areaid = ProtoField.ipv4("pwospf.areaid", "Area ID")
f.checksum = ProtoField.uint16("pwospf.checksum", "Checksum", base.HEX)
f.authtype = ProtoField.uint16("pwospf.authtype", "Autype", base.HEX)
f.authentication = ProtoField.uint64("pwospf.authentication", "Authentication", base.HEX)

f.netmask = ProtoField.ipv4("pwospf.netmask", "Network Mask")
f.helloint = ProtoField.uint16("pwospf.helloint", "HelloInt", base.DEC)
f.padding = ProtoField.uint16("pwospf.padding", "Padding", base.HEX)

f.sequnce = ProtoField.uint16("pwospf.sequnce", "Sequence", base.DEC)
f.ttl = ProtoField.uint16("pwospf.ttl", "TTL", base.DEC)
f.numadvertisements = ProtoField.uint16("pwospf.numadvertisements", "# advertisements", base.DEC)

f.lsusubnet = ProtoField.ipv4("pwospf.lsusubnet", "Subnet")
f.lsumask = ProtoField.ipv4("pwospf.lsumask", "Mask")
f.lsurouterid = ProtoField.ipv4("pwospf.lsurouterid", "Router ID")
f.lsumetric = ProtoField.uint32("pwospf.lsumetric", "Metric")

function p_pwospf.dissector(buffer, pinfo, tree)
if buffer:len() == 0 then
return
end

subtree = tree:add(p_pwospf, buffer(0))
subtree:add(f.ver, buffer(0, 1))
subtree:add(f.tp, buffer(1, 1))
subtree:add(f.length, buffer(2, 2))
subtree:add(f.routerid, buffer(4, 4))
subtree:add(f.areaid, buffer(8, 4))
subtree:add(f.checksum, buffer(12, 2))
subtree:add(f.authtype, buffer(14, 2))
subtree:add(f.authentication, buffer(16, 8))

local tp = buffer(1, 1):uint()

if tp == 1 then
subtree:add(f.netmask, buffer(24, 4))
subtree:add(f.helloint, buffer(28, 2))
subtree:add(f.padding, buffer(30, 2))
pinfo.cols.protocol = "PWOSPF (Hello)"
elseif tp == 4 then
subtree:add(f.sequnce, buffer(24, 2))
subtree:add(f.ttl, buffer(26, 2))
subtree:add(f.numadvertisements, buffer(28, 4))

local numadvertisements = buffer(28, 4):uint()

local i = 0

while i < numadvertisements do
local subtree2 = subtree:add('Link state advertisement ' .. i)
subtree2:add(f.lsusubnet, buffer(32 + i * 16, 4))
subtree2:add(f.lsumask, buffer(36 + i * 16, 4))
subtree2:add(f.lsurouterid, buffer(40 + i * 16, 4))
subtree2:add(f.lsumetric, buffer(44 + i * 16, 4))

i = i + 1
end

pinfo.cols.protocol = "PWOSPF (LSU)"
else
pinfo.cols.protocol = p_pwospf.name

end

pinfo.cols.info = ""

end

function p_pwospf.init()
end

local ip_dissector_table = DissectorTable.get("ip.proto")
ip_dissector_table:add(89, p_pwospf)

0 comments on commit 6170186

Please sign in to comment.