Skip to content

Commit 6ca9ee2

Browse files
Merge branch 'dev' of github.com:hioa-cs/IncludeOS into dev
2 parents 68296ea + f0a5a73 commit 6ca9ee2

60 files changed

Lines changed: 847 additions & 213 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

api/fs/common.hpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@
2828

2929
namespace fs {
3030

31-
// Generic structure for directory entries
3231
struct Dirent;
33-
32+
struct File_system;
3433

3534
/**
3635
* @brief Type used as a building block to represent buffers
@@ -185,24 +184,23 @@ namespace fs {
185184
/** @var no_error: Always returns boolean false when used in expressions */
186185
extern error_t no_error;
187186

188-
/** Async function types **/
189-
using on_init_func = delegate<void(error_t)>;
187+
/** Async function types **/
188+
using on_init_func = delegate<void(error_t, File_system&)>;
190189
using on_ls_func = delegate<void(error_t, dirvec_t)>;
191190
using on_read_func = delegate<void(error_t, buffer_t, uint64_t)>;
192191
using on_stat_func = delegate<void(error_t, const Dirent&)>;
193192

194193

195-
struct List {
194+
struct List
195+
{
196196
error_t error;
197197
dirvec_t entries;
198198
auto begin() { return entries->begin(); }
199199
auto end() { return entries->end(); }
200200
auto cbegin() { return entries->cbegin(); }
201201
auto cend() { return entries->cend(); }
202-
203202
};
204203

204+
} //< fs
205205

206-
} //< namespace fs
207-
208-
#endif //< FS_ERROR_HPP
206+
#endif //< FS_COMMON_HPP

api/fs/disk.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ namespace fs {
4242

4343
struct Partition;
4444
using on_parts_func = delegate<void(fs::error_t, std::vector<Partition>&)>;
45-
using on_init_func = delegate<void(fs::error_t)>;
45+
using on_init_func = delegate<void(fs::error_t, File_system&)>;
4646
using lba_t = uint32_t;
4747

4848
enum partition_t {

api/fs/filesystem.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ namespace fs {
2727
struct Dirent;
2828

2929
struct File_system {
30-
31-
/** Initialize this filesystem with LBA at @base_sector */
32-
virtual void init(uint64_t lba, uint64_t size, on_init_func on_init) = 0;
33-
3430
/** Get unique (per device type) device id for underlying device.*/
3531
virtual Device_id device_id() = 0;
3632

@@ -76,6 +72,9 @@ namespace fs {
7672
/** Returns the name of this filesystem */
7773
virtual std::string name() const = 0;
7874

75+
/** Initialize this filesystem with LBA at @base_sector */
76+
virtual void init(uint64_t lba, uint64_t size, on_init_func on_init) = 0;
77+
7978
/** Default destructor */
8079
virtual ~File_system() noexcept = default;
8180
}; //< class File_system

api/net/buffer_store.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,10 @@ namespace net
8282
std::vector<buffer_t> available_;
8383
int cpu;
8484
static bool smp_enabled_;
85+
#ifndef INCLUDEOS_SINGLE_THREADED
8586
// has strict alignment reqs, so put at end
8687
spinlock_t plock;
87-
88+
#endif
8889
BufferStore(BufferStore&) = delete;
8990
BufferStore(BufferStore&&) = delete;
9091
BufferStore& operator=(BufferStore&) = delete;

api/net/http/connection.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ namespace http {
6767
inline TCP_conn release();
6868

6969
/**
70-
* @brief Wether the underlying TCP connection has been released or not
70+
* @brief Whether the underlying TCP connection has been released or not
7171
*
7272
* @return true if the underlying TCP connection is released
7373
*/

api/net/http/message.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class Message {
9999
*
100100
* @param[in] len The length of the content
101101
*
102-
* @return Outcome of wether the field got updated or not
102+
* @return Outcome of whether the field got updated or not
103103
*/
104104
inline bool set_content_length(size_t len);
105105

api/net/inet.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ namespace net {
100100
virtual void force_start_send_queues() = 0;
101101

102102
virtual void move_to_this_cpu() = 0;
103+
virtual int get_cpu_id() const noexcept = 0;
103104

104105
}; //< class Inet<LINKLAYER, IPV>
105106
} //< namespace net

api/net/inet4.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ namespace net {
194194

195195
void move_to_this_cpu() override;
196196

197+
int get_cpu_id() const noexcept override {
198+
return this->cpu_id;
199+
}
200+
197201
/** Return the stack on the given Nic */
198202
template <int N = 0>
199203
static auto&& stack()
@@ -248,6 +252,7 @@ namespace net {
248252

249253
std::shared_ptr<net::DHClient> dhcp_{};
250254

255+
int cpu_id;
251256
const uint16_t MTU_;
252257

253258
friend class Super_stack;

api/net/router.hpp

Lines changed: 62 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,41 @@ namespace net {
3131
using Addr = typename IPV::addr;
3232
using Netmask = typename IPV::addr;
3333

34-
Addr dest_net()
35-
{ return dest_net_; }
34+
Addr net() const noexcept
35+
{ return net_; }
3636

37-
Netmask netmask()
37+
Netmask netmask() const noexcept
3838
{ return netmask_; }
3939

40-
Addr gateway()
40+
Addr gateway() const noexcept
4141
{ return gateway_; }
4242

43-
int cost()
43+
int cost() const noexcept
4444
{ return cost_; }
4545

46-
Stack_ptr interface()
46+
Stack_ptr interface() const noexcept
4747
{ return iface_; };
4848

49-
Route(Addr dest_net, Netmask mask, Addr gateway, Stack& iface, int cost)
50-
: dest_net_{dest_net}, netmask_{mask}, gateway_{gateway}, iface_{&iface}, cost_{cost}
49+
Stack_ptr match(typename IPV::addr dest) const noexcept
50+
{ return (dest & netmask_) == net_ ? iface_ : nullptr; }
51+
52+
bool operator<(const Route& b) const
53+
{ return cost() < b.cost(); }
54+
55+
bool operator==(const Route& b) const
56+
{
57+
return net_ == b.net() and
58+
netmask_ == b.netmask() and
59+
cost_ == b.cost() and
60+
iface_ == b.interface();
61+
}
62+
63+
Route(Addr net, Netmask mask, Addr gateway, Stack& iface, int cost)
64+
: net_{net}, netmask_{mask}, gateway_{gateway}, iface_{&iface}, cost_{cost}
5165
{}
5266

5367
private:
54-
Addr dest_net_;
68+
Addr net_;
5569
Netmask netmask_;
5670
Addr gateway_;
5771
Stack_ptr iface_;
@@ -82,33 +96,62 @@ namespace net {
8296
{ return Forward_delg(*this, forward); }
8397

8498

85-
/** Get the interface route for a certain IP **/
86-
virtual Stack_ptr get_interface(typename IPV::addr dest) {
99+
/** Get any interface route for a certain IP **/
100+
Route<IPV>* get_first_route(typename IPV::addr dest) {
87101

88102
for (auto&& route : routing_table_) {
89-
if ((dest & route.netmask()) == route.dest_net())
90-
return route.interface();
103+
Stack_ptr match = route.match(dest);
104+
if (match) return &route;
91105
}
92106

93107
return nullptr;
108+
};
94109

110+
/** Get any interface route for a certain IP **/
111+
Stack_ptr get_first_interface(typename IPV::addr dest) {
112+
auto route = get_first_route(dest);
113+
if (route) return route->interface();
114+
return nullptr;
95115
};
96116

117+
/** Check if there exists a route for a given IP **/
97118
bool route_check(typename IPV::addr dest){
98-
return get_interface(dest);
119+
return get_first_interface(dest) != nullptr;
99120
}
100121

101122

123+
/**
124+
* Get all routes for a certain IP
125+
* @todo : Optimize!
126+
**/
127+
Routing_table get_all_routes(typename IPV::addr dest) {
128+
129+
Routing_table t;
130+
std::copy_if(routing_table_.begin(),
131+
routing_table_.end(),
132+
std::back_inserter(t), [dest](const Route<IPV>& route) {
133+
return route.match(dest);
134+
});
135+
return t;
136+
}
137+
138+
/**
139+
* Get cheapest route for a certain IP
140+
* @todo : Optimize!
141+
**/
142+
Route<IPV>* get_cheapest_route(typename IPV::addr dest) {
143+
Routing_table all = get_all_routes(dest);
144+
std::sort(all.begin(), all.end());
145+
if (not all.empty()) return &all.front();
146+
return nullptr;
147+
};
148+
102149

103150
/** Construct a router over a set of interfaces **/
104-
Router(Interfaces& ifaces, Routing_table&& tbl = {})
151+
Router(Interfaces& ifaces, Routing_table tbl = {})
105152
: networks_{ifaces}, routing_table_{tbl}
106153
{ }
107154

108-
void set_routing_table(Routing_table&& tbl) {
109-
routing_table_ = std::forward(tbl);
110-
};
111-
112155
void set_routing_table(Routing_table tbl) {
113156
routing_table_ = tbl;
114157
};

api/net/tcp/connection.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ class Connection : public std::enable_shared_from_this<Connection> {
786786
void writeq_reset();
787787

788788
/*
789-
Mark wether the Connection is in TCP write queue or not.
789+
Mark whether the Connection is in TCP write queue or not.
790790
*/
791791
void set_queued(bool queued)
792792
{ queued_ = queued; }
@@ -1046,7 +1046,7 @@ class Connection : public std::enable_shared_from_this<Connection> {
10461046
void timewait_timeout()
10471047
{ signal_close(); }
10481048

1049-
/** Wether to use Delayed ACK or not */
1049+
/** Whether to use Delayed ACK or not */
10501050
bool use_dack() const noexcept;
10511051

10521052
/**

0 commit comments

Comments
 (0)