<commit_before>module KitchenSink (sink, main) where

import Arp (doArp)
import MacLearning (learningSwitch)

import Control.Concurrent
import Data.ByteString.Lazy (ByteString)
import qualified Data.Set as Set

import Frenetic.NetCore
import Frenetic.Slices.Compile (dynamicTransform)
import Frenetic.Slices.Slice (simpleSlice)
import Frenetic.Topo (buildGraph)

topo = buildGraph [ ((2, 0), (1, 1))
                  , ((3, 0), (1, 2)) ]

spy = do
  spyChan <- newChan
  (query, action) <- getPkts
  writeChan spyChan (matchAll ==> action)
  return spyChan

-- |Run a number of examples wrapped in slices.
-- * Arp in a slice that only accepts ARP packets
-- * Learning Switch in a slice that only accepts ipv4 packets
-- Note that this is built to only work on the default mininet topology of
-- H2 --1 S1 2-- H3
sink :: IO (Chan Policy) -> IO (Chan Policy, Chan (Loc, ByteString))
sink routing = do
  route <- routing
  arpRoute <- routing
  spyPolicy <- spy
  let routeSlice = simpleSlice topo (neg $ dlTyp 0x0806)
  let arpSlice = simpleSlice topo (dlTyp 0x0806)
  let spySlice = simpleSlice topo matchAll
  (arpPolicy, arpPacket) <- doArp arpRoute
  policies <- dynamicTransform [ (routeSlice, route)
                               , (arpSlice, arpPolicy)
                               , (spySlice, spyPolicy)
                               ]
  return (policies, arpPacket)

main = do
  (policies, packets) <- sink learningSwitch
  dynController policies packets<commit_msg>Add monitor to kitchen sink<commit_after>module KitchenSink (sink, main) where

import Arp (doArp)
import MacLearning (learningSwitch)
import Monitor (monitor)

import Control.Concurrent
import Data.ByteString.Lazy (ByteString)
import qualified Data.Set as Set

import Frenetic.NetCore
import Frenetic.Slices.Compile (dynamicTransform)
import Frenetic.Slices.Slice (simpleSlice)
import Frenetic.Topo (buildGraph)

-- This is the default topology when you start mininet without parameters
topo = buildGraph [ ((2, 0), (1, 1))
                  , ((3, 0), (1, 2)) ]

spy = do
  spyChan <- newChan
  (byteChan, action) <- countBytes 10000 -- every 10 seconds
  writeChan spyChan (matchAll ==> action)
  return spyChan

-- |Run a number of examples wrapped in slices.
-- * Arp in a slice that only accepts ARP packets
-- * Learning Switch in a slice that only accepts ipv4 packets
-- Note that this is built to only work on the default mininet topology of
-- H2 --1 S1 2-- H3
sink :: IO (Chan Policy) -> IO (Chan Policy, Chan (Loc, ByteString))
sink routing = do
  route <- routing
  arpRoute <- routing
  monitorRoute <- routing
  spyPolicy <- spy
  -- Just ARP
  let arpSlice = simpleSlice topo (dlTyp 0x0806)
  -- Just ICMP (ping)
  let monitorSlice = simpleSlice topo (dlTyp 0x0800 <&&> nwProto 0x01)
  -- Everything else
  let routeSlice = simpleSlice topo (neg $ (dlTyp 0x0806 <||>
                                           (dlTyp 0x0800 <&&> nwProto 0x01)))
  let spySlice = simpleSlice topo matchAll
  (arpPolicy, arpPacket) <- doArp arpRoute
  monitorPolicy <- monitor monitorRoute
  policies <- dynamicTransform [ (routeSlice, route)
                               , (arpSlice, arpPolicy)
                               , (monitorSlice, monitorPolicy)
                               , (spySlice, spyPolicy)
                               ]
  return (policies, arpPacket)

main = do
  (policies, packets) <- sink learningSwitch
  dynController policies packets
{'fraction_non_alphanumeric': 0.09138381201044386, 'fraction_numerical': 0.020597621119814332, 'mean_word_length': 2.7848518111964875, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2734045', 'n_tokens_mistral': 1114, 'n_tokens_neox': 1033, 'n_words': 371}