Skip to content

Commit

Permalink
Merge pull request #27 from amlight/fix/of_13
Browse files Browse the repository at this point in the history
Fixing issues related to openflow 1.3
  • Loading branch information
jab1982 authored Nov 8, 2024
2 parents 4b79b6c + e4eb1ff commit 0d907da
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 132 deletions.
41 changes: 21 additions & 20 deletions apps/influx_client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import datetime
import logging
import requests
Expand All @@ -13,9 +14,9 @@ class InfluxClient(object):
"""Class responsible for connecting to InfluxDB and send data"""

def __init__(self,
host='localhost',
port=8086,
db='root',
host=os.environ.get("OFP_SNIFFER_INFLUX_HOST", "localhost"),
port=int(os.environ.get("OFP_SNIFFER_INFLUX_PORT", 8086)),
db=os.environ.get("OFP_SNIFFER_INFLUX_DB", "root"),
trigger_event=''):
"""Connect to influxdb
Expand Down Expand Up @@ -89,23 +90,24 @@ def _update_tcp_reconnects(self):

def _update_per_dpid(self):
""" This method updates stats per dpid on InfluxDB
TODO: currently, OFStats().per_dev_packet_type is empty
"""
dpids = OFStats().per_dev_packet_types.keys()
self.logger.debug("dpids: {0}".format(dpids))
for dpid in dpids:
json_body = [{
"measurement":
"OFP_messages",
"tags": {
"dpid": dpid
},
"time":
"{0}".format(datetime.datetime.utcnow().isoformat('T')),
"fields":
OFStats().per_dev_packet_types[dpid]
}]
for dpid, ver_stats in OFStats().per_dev_packet_types.items():
json_body = []
for v, fields in ver_stats.items():
if not isinstance(fields, dict):
continue
json_body.append({
"measurement":
"OFP_messages",
"tags": {
"dpid": dpid,
"OFP_version": v
},
"time":
"{0}".format(datetime.datetime.utcnow().isoformat('T')),
"fields": fields
})
self.logger.debug(json_body)
self.db_client.write_points(json_body)

Expand All @@ -119,8 +121,7 @@ def _update_db(self):
self.trigger_event.clear()
try:
self._update_packet_types()
# TODO: increment per dpid too
# self._update_per_dpid()
self._update_per_dpid()
self._update_tcp_reconnects()
except requests.exceptions.ConnectionError:
self.logger.error("couldn't write data to influxdb.")
Expand Down
6 changes: 2 additions & 4 deletions apps/ofp_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,7 @@ def process_per_dev_packet_types(self, pkt, ofp):
self.per_dev_packet_types[dpid] = self.init_type_packets(version)
self.per_dev_packet_types[dpid]['total'] = 0

message_type = str(ofp.header.message_type)
message_type = message_type.split('.')[1]
message_type = ofp.header.message_type.name
try:
self.per_dev_packet_types[dpid][version][message_type] += 1
except KeyError:
Expand All @@ -206,8 +205,7 @@ def process_packet(self, pkt):
for of_msg in pkt.ofmsgs:
# Supporting /ofp_stats/packet_totals
version = str(of_msg.ofp.header.version.value)
message_type = str(of_msg.ofp.header.message_type)
message_type = message_type.split('.')[1]
message_type = of_msg.ofp.header.message_type.name
try:
self.packet_types[version][message_type] += 1
except KeyError:
Expand Down
13 changes: 2 additions & 11 deletions docs/filters.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
{
"allowed_of_versions": {
"1.0": {
"rejected_of_types": [
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 26, 27, 28, 29
]
},
"1.3": {
"rejected_of_types": [

20, 21, 22, 23, 24, 25, 26, 27, 28, 29
]
}
},
"filters":{
"ethertypes": {
"lldp" : 0,
"lldp" : 1,
"fvd" : 0,
"arp" : 0,
"others": [ "88b5" ]
"others": [ ]
},
"packetIn_filter": {
"switch_dpid": "any",
Expand Down
9 changes: 5 additions & 4 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
termcolor
hexdump
netaddr
pcapy
python-openflow
flask
pcapy-ng
python-openflow@https://github.com/kytos-ng/python-openflow/archive/2023.2.0.zip
flask==2.3.3
Werkzeug==2.3.8
influxdb
pyaml
requests
requests
Loading

0 comments on commit 0d907da

Please sign in to comment.