Skip to content

Commit

Permalink
Changed the micronet/device storage to use json files instead of dnsm…
Browse files Browse the repository at this point in the history
…asq files

micronet/device data will now be saved to files micronets.json
 and micronets-devices.json instead of being written into comments
 in the dnsmasq file.

Also reworked/simplified the configs
  • Loading branch information
craigpratt committed Nov 27, 2020
1 parent 5376624 commit ec491a5
Show file tree
Hide file tree
Showing 14 changed files with 334 additions and 439 deletions.
2 changes: 1 addition & 1 deletion distribution/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: all clean distclean deb scp

VERSION=1.0.63
VERSION=1.0.64
DIST=U18.04
FBASE=micronets-gw
SDIRS=../filesystem
Expand Down
74 changes: 74 additions & 0 deletions filesystem/opt/micronets-gw/doc/interfaces.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Note: The contained entries should augment the system-provided /etc/network/interfaces file.
# IOW, this file should not over-write the existing /etc/network/interfaces on
# your system.

#
# create an Openvswitch bridge
# on the commandline: ovs-vsctl add-br brmn001
#
auto brmn001
allow-ovs brmn001
iface brmn001 inet dhcp
ovs_type OVSBridge
# This is the port that's connected to the Internet
ovs_bridge_uplink_port enp3s0
# the ovs_ports should list all wired and wireless interfaces under control of Mironets
ovs_ports enp3s0 wlp2s0 enxac7f3ee61832 enx00e04c534458
# The ovs_manager line is for future support - leave commented out for now
# ovs_manager tcp:1.2.3.4:6640
ovs_protocols OpenFlow10,OpenFlow11,OpenFlow12,OpenFlow13

# Assign IP addresses to the bridge that may be configured as Micronets
# Note: This will be replaced with dynamic route table entries in the near future

iface brmn001 inet static
address 192.168.250.1
netmask 255.255.255.0

iface brmn001 inet static
address 192.168.251.1
netmask 255.255.255.0

iface brmn001 inet static
address 192.168.252.1
netmask 255.255.255.0

# Attach physical ports to the bridge (requesting particular port numbers)

# This entry would represent the trunk/uplink interface (the interface with
# a configured gateway). This can be configured with a fixed IP or DHCP, as
# documented in the interfaces man page
allow-brmn001 enp3s0
iface enp3s0 inet manual
ovs_type OVSPort
ovs_bridge brmn001
ovs_port_req 2
ovs_port_initial_state enabled

# A wireless interface
allow-brmn001 wlp2s0
iface wlp2s0 inet manual
ovs_type OVSPort
# The ovs_bridge must match the bridge definition (above)
ovs_bridge brmn001
# The port number needs to be unique for the bridge
ovs_port_req 3
# Indicates that the port is blocked at startup (until enabled via command)
ovs_port_initial_state blocked

# A wired interface
allow-brmn001 enxac7f3ee61832
iface enxac7f3ee61832 inet manual
ovs_type OVSPort
ovs_bridge brmn001
ovs_port_req 4
ovs_port_initial_state blocked

# A second wired interface
allow-brmn001 enx00e04c534458
iface enx00e04c534458 inet manual
ovs_type OVSPort
ovs_bridge brmn001
ovs_port_req 5
ovs_port_initial_state blocked

4 changes: 2 additions & 2 deletions micronets-gw-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ source /opt/local/bin/virtualenvwrapper.sh-2.7
If you want to access the REST API directly - running against the mock gateway adapter, use:

```
python ./runner.py -c config.MockDevelopmentConfig
python ./runner.py -c config.LocalDevelopmentConfig
```

If you want to have the gateway service connect to a websocket for access to the REST API and to receive notifications,
Expand All @@ -71,7 +71,7 @@ that can be used to verify the authenticity of the websocket server.
In this case, you can start the Micronets gateway service using:

```
python ./runner.py -c config.MockDevelopmentConfigWithWebsocket
python ./runner.py -c config.LocalDevelopmentConfigWithWebsocket
```

To exit the virtual environment use `deactivate`. You can continue working with the Micronets gateway service by running `workon micronets-gw-service`.
Expand Down
53 changes: 35 additions & 18 deletions micronets-gw-service/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def on_json_loading_failed(self, error: Exception) -> None:
class MyQuart (Quart):
request_class = MyRequest

logger = logging.getLogger ('micronets-gw-service')
logger = logging.getLogger('micronets-gw-service')

# create application instance
app = MyQuart (__name__)
Expand All @@ -35,20 +35,27 @@ class MyQuart (Quart):
elif (config_env):
config = config_env
else:
config = 'config.MockDevelopmentConfig'
config = 'config.LocalDevelopmentConfig'

print (f"Running with config {config}")
print(f"Running with config {config}")

app.config.from_object (config)

logging_filename = app.config.get('LOGFILE_PATH')
logging_filemode = app.config.get('LOGFILE_MODE')
logging_level = app.config.get('LOGGING_LEVEL')
logging.basicConfig (level=logging_level, filename=logging_filename, filemode=logging_filemode,
format='%(asctime)s %(name)s: %(levelname)s %(message)s')
print (f"Logging to logfile {logging_filename} (level {logging_level})")

logger.info (f"Loading app module using {config}")
if logging_filename:
logging_format = '%(asctime)s %(name)s: %(levelname)s %(message)s'
logging.basicConfig(level=logging_level, filename=logging_filename, filemode=logging_filemode,
format=logging_format)
print(f"Logging to logfile {logging_filename} (level {logging_level})")
else:
logging_format = '%(name)s: %(levelname)s %(message)s'
logging.basicConfig (level=logging_level, format=logging_format)
print (f"Logging to standard out (level {logging_level})")

logger.info (f"Running with config {config}")

def get_logger():
return logger
Expand Down Expand Up @@ -76,13 +83,23 @@ def get_dpp_handler():
if subscriber_id:
logger.info(f"Subscriber ID override: \"{subscriber_id}\"")

db_adapter = None
adapter = app.config.get('DB_ADAPTER')
if not adapter:
exit ("Missing DB_ADAPTER setting in config")
if adapter.upper() == "JSONDBFILEADAPTER":
from .json_file_db_adapter import JsonFileDBAdapter
logger.info ("Using JSON file adapter for DB")
db_adapter = JsonFileDBAdapter (app.config)
else:
exit (f"Unrecognized DB_ADAPTER type ({adapter})")

dhcp_adapter = None
adapter = app.config ['DHCP_ADAPTER'].upper ()
if adapter == "MOCK":
from .mock_adapter import MockAdapter
logger.info ("Using MOCK adapter")
dhcp_adapter = MockAdapter ()
elif adapter == "ISCDHCP":
adapter = app.config.get('DHCP_ADAPTER')
if not adapter:
exit ("Missing DHCP_ADAPTER setting in config")
adapter = adapter.upper()
if adapter == "ISCDHCP":
from .isc_dhcpd_adapter import IscDhcpdAdapter
logger.info ("Using ISC DHCP adapter")
dhcp_adapter = IscDhcpdAdapter (app.config)
Expand All @@ -91,7 +108,7 @@ def get_dpp_handler():
logger.info ("Using DNSMASQ adapter")
dhcp_adapter = DnsMasqAdapter (app.config)
else:
exit ("Unrecognized adapter type ({})".format (adapter))
exit (f"Unrecognized DHCP_ADAPTER type ({adapter})")

from .ws_connector import WSConnector

Expand Down Expand Up @@ -166,10 +183,10 @@ def get_dpp_handler():

conf_model = None
try:
min_dhcp_conf_update_int_s = app.config ['MIN_DHCP_UPDATE_INTERVAL_S']
logger.info (f"Minimum DHCP update interval (seconds): {min_dhcp_conf_update_int_s}")
conf_model = GatewayServiceConf (ws_connector, dhcp_adapter, flow_adapter, hostapd_adapter,
min_dhcp_conf_update_int_s)
adapter_update_int_s = app.config ['ADAPTER_UPDATE_INTERVAL_S']
logger.info (f"Adapter update interval (seconds): {adapter_update_int_s}")
conf_model = GatewayServiceConf (ws_connector, db_adapter, dhcp_adapter, flow_adapter, hostapd_adapter,
adapter_update_int_s)
except Exception as ex:
logger.info ("Error starting with adapter:", exc_info=True)
exit (1)
Expand Down
Loading

0 comments on commit ec491a5

Please sign in to comment.