diff --git a/lib/NPEP.spec.md b/lib/NPEP.spec.md new file mode 100644 index 0000000..a0476bc --- /dev/null +++ b/lib/NPEP.spec.md @@ -0,0 +1,31 @@ +# Netrave Packet Exchange Protocol (NPEP) + +## Overview + +NPEP is a custom protocol designed for the NETRAVE project to facilitate communication between the Orchestrator and the Packet Processor Consumers. It is designed to be lightweight, efficient, and secure. + +## Message Types + +NPEP supports the following message types: + +1. `REQUEST`: Used by a consumer to request a new pcap chunk from the Orchestrator or to request permission to output a processed pcap chunk. The format is `REQUEST {CONSUMER_ID} {REQUEST_TYPE} {PCAP_CHUNK_ID}` where `{REQUEST_TYPE}` can be either `NEW` for a new pcap chunk or `OUTPUT` for output permission. + +2. `UPSTATE`: Used by a consumer to update its state in the Orchestrator. The format is `UPSTATE {CONSUMER_ID} {STATE} {PCAP_CHUNK_ID}` where `{STATE}` is the current state of the consumer. The states can be `RECEIVED`, `PROCESSING`, `STASIS`, or `AT_REST`. + +3. `FINISHED`: Used by a consumer to inform the Orchestrator that it has finished processing a pcap chunk. The format is `FINISHED {CONSUMER_ID} {PCAP_CHUNK_ID}`. + +4. `CHANGE`: Used by the Orchestrator to request a consumer to change its state. The format is `CHANGE {CONSUMER_ID} {STATE} {URGENCY}` where `{STATE}` is the state the Orchestrator wants the consumer to change to and `{URGENCY}` is the urgency level of the state change request. The urgency levels can be `PLS` (Please), `SOON`, or `NOW`. + +5. `SHUTDOWN`: Used by the Orchestrator to request a consumer to shut down. The format is `SHUTDOWN {CONSUMER_ID} {URGENCY}` where `{URGENCY}` is the urgency level of the shutdown request. The urgency levels can be `PLS` (Please), `SOON`, or `NOW`. + +## Security + +To ensure only legitimate consumers can connect to the Orchestrator, a unique `{HASH}` is generated by the Orchestrator and used to authenticate each consumer. This `{HASH}` is included in the `REQUEST` message. + +## Error Handling + +If a consumer crashes or disconnects unexpectedly, the Orchestrator will detect this through a lack of heartbeat messages and reassign the pcap chunk to another consumer. + +## Data Transmission + +NPEP is designed to transmit pcap data in its raw binary form to minimize overhead and maximize efficiency. The Orchestrator sends pcap data to the consumers using the `SEND PCAP {PCAP_CHUNK_ID} {PCAP_DATA}` message, where `{PCAP_DATA}` is the raw pcap data. diff --git a/lib/go.mod b/lib/go.mod new file mode 100644 index 0000000..7fcc655 --- /dev/null +++ b/lib/go.mod @@ -0,0 +1,8 @@ +module pixelridgesoftworks.com/NETRAVE + +go 1.20 + +require ( + github.com/google/gopacket v1.1.19 // indirect + golang.org/x/sys v0.0.0-20190412213103-97732733099d // indirect +) diff --git a/lib/go.sum b/lib/go.sum new file mode 100644 index 0000000..aea2a4a --- /dev/null +++ b/lib/go.sum @@ -0,0 +1,15 @@ +github.com/google/gopacket v1.1.19 h1:ves8RnFZPGiFnTS0uPQStjwru6uO6h+nlr9j6fL7kF8= +github.com/google/gopacket v1.1.19/go.mod h1:iJ8V8n6KS+z2U1A8pUwu8bW5SyEMkXJB8Yo/Vo+TKTo= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/lib/packet-cap.go b/lib/packet-cap.go new file mode 100644 index 0000000..7466a12 --- /dev/null +++ b/lib/packet-cap.go @@ -0,0 +1,34 @@ +package main + +import ( + "fmt" + "log" + "time" + + "github.com/google/gopacket" + "github.com/google/gopacket/pcap" +) + +var ( + device string = "netrave0" + snapshot_len int32 = 2048 + promiscuous bool = false + err error + timeout time.Duration = 30 * time.Second + handle *pcap.Handle +) + +func main() { + // Open device + handle, err = pcap.OpenLive(device, snapshot_len, promiscuous, timeout) + if err != nil { + log.Fatal(err) + } + defer handle.Close() + + // Use the handle as a packet source to process all packets + packetSource := gopacket.NewPacketSource(handle, handle.LinkType()) + for packet := range packetSource.Packets() { + fmt.Println(packet) // Do something with a packet here. + } +}