<commit_before><commit_msg>net: Added link layer driver which takes a link protocol<commit_after>

#pragma once
#ifndef NET_LINK_LAYER_HPP
#define NET_LINK_LAYER_HPP

#include <hw/nic.hpp>

namespace net {

template <class Protocol>
class Link_layer : public hw::Nic {
public:
  using upstream    = hw::Nic::upstream;
  using downstream  = hw::Nic::downstream;
public:
  explicit Link_layer(Protocol&& protocol, uint32_t bufstore_sz, uint16_t bufsz);

  downstream create_link_downstream() override
  { return {link_, &Protocol::transmit}; }

  void set_ip4_upstream(upstream handler) override
  { link_.set_ip4_upstream(handler); }

  void set_ip6_upstream(upstream handler) override
  { link_.set_ip6_upstream(handler); }

  void set_arp_upstream(upstream handler) override
  { link_.set_arp_upstream(handler); }

protected:
  /** Called by the underlying physical driver inheriting the Link_layer */
  void receive(net::Packet_ptr pkt)
  { link_.receive(std::move(pkt)); }

private:
  Protocol link_;
};

template <class Protocol>
Link_layer<Protocol>::Link_layer(Protocol&& protocol, uint32_t bufstore_sz, uint16_t bufsz)
  : hw::Nic(bufstore_sz + Protocol::header_size(), bufsz),
    link_{std::forward<Protocol>(protocol)}
{
}

} // < namespace net

#endif

{'fraction_non_alphanumeric': 0.11163895486935867, 'fraction_numerical': 0.009501187648456057, 'mean_word_length': 5.832432432432433, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1740999', 'n_tokens_mistral': 432, 'n_tokens_neox': 415, 'n_words': 96}