Skip to content

Commit

Permalink
implemented suport for NortelDiscovery
Browse files Browse the repository at this point in the history
  • Loading branch information
dreadl0ck committed Jan 13, 2019
1 parent 88fe7ae commit e5e0b5f
Show file tree
Hide file tree
Showing 7 changed files with 976 additions and 692 deletions.
36 changes: 36 additions & 0 deletions encoder/nortelDiscovery.go
@@ -0,0 +1,36 @@
/*
* NETCAP - Traffic Analysis Framework
* Copyright (c) 2017 Philipp Mieden <dreadl0ck [at] protonmail [dot] ch>
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

package encoder

import (
"github.com/dreadl0ck/netcap/types"
"github.com/golang/protobuf/proto"
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
)

var nortelDiscoveryEncoder = CreateLayerEncoder(types.Type_NC_NortelDiscovery, layers.LayerTypeNortelDiscovery, func(layer gopacket.Layer, timestamp string) proto.Message {
if nortel, ok := layer.(*layers.NortelDiscovery); ok {
return &types.NortelDiscovery{
Timestamp: timestamp,
IPAddress: string(nortel.IPAddress),
SegmentID: []byte(nortel.SegmentID),
Chassis: int32(nortel.Chassis),
Backplane: int32(nortel.Backplane),
State: int32(nortel.State),
NumLinks: int32(nortel.NumLinks),
}
}
return nil
})
2 changes: 2 additions & 0 deletions netcap.go
Expand Up @@ -140,6 +140,8 @@ func InitRecord(typ types.Type) (record proto.Message) {
record = new(types.CiscoDiscovery)
case types.Type_NC_CiscoDiscoveryInfo:
record = new(types.CiscoDiscoveryInfo)
case types.Type_NC_NortelDiscovery:
record = new(types.NortelDiscovery)
default:
panic("InitRecord: unknown type: " + typ.String())
}
Expand Down
10 changes: 10 additions & 0 deletions netcap.proto
Expand Up @@ -131,6 +131,7 @@ enum Type {
NC_CiscoDiscovery = 83;
NC_CiscoDiscoveryInfo = 84;
NC_USBRequestBlockSetup = 85;
NC_NortelDiscovery = 86;
}

/*
Expand Down Expand Up @@ -1432,3 +1433,12 @@ message IPNet {
string IPMask = 2; // network mask
}

message NortelDiscovery {
string Timestamp = 1;
string IPAddress = 2;
bytes SegmentID = 3;
int32 Chassis = 4;
int32 Backplane = 5;
int32 State = 6;
int32 NumLinks = 7;
}
1,473 changes: 784 additions & 689 deletions types/netcap.pb.go

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions types/netcap_pb.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

92 changes: 89 additions & 3 deletions types/netcap_pb2.py

Large diffs are not rendered by default.

44 changes: 44 additions & 0 deletions types/nortelDiscovery.go
@@ -0,0 +1,44 @@
/*
* NETCAP - Traffic Analysis Framework
* Copyright (c) 2017 Philipp Mieden <dreadl0ck [at] protonmail [dot] ch>
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

package types

import "encoding/hex"

func (a NortelDiscovery) CSVHeader() []string {
return filter([]string{
"Timestamp",
"IPAddress", // string
"SegmentID", // []byte
"Chassis", // int32
"Backplane", // int32
"State", // int32
"NumLinks", // int32
})
}

func (a NortelDiscovery) CSVRecord() []string {
return filter([]string{
formatTimestamp(a.Timestamp),
a.IPAddress, // string
hex.EncodeToString(a.SegmentID), // []byte
formatInt32(a.Chassis), // int32
formatInt32(a.Backplane), // int32
formatInt32(a.State), // int32
formatInt32(a.NumLinks), // int32
})
}

func (a NortelDiscovery) NetcapTimestamp() string {
return a.Timestamp
}

0 comments on commit e5e0b5f

Please sign in to comment.