-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generated from commit d9161f2d0f58197fb6d7a30f2ad0c25163edbc8d
- Loading branch information
Showing
23 changed files
with
11,857 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/) | |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.