Skip to content

Commit 2df49bf

Browse files
committed
[feature] Openwrt: Add support for mwan3
1 parent a16a91f commit 2df49bf

4 files changed

Lines changed: 242 additions & 2 deletions

File tree

netjsonconfig/backends/openwrt/converters/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from .switch import Switch
1111
from .wireguard_peers import WireguardPeers
1212
from .wireless import Wireless
13+
from .mwan3 import Mwan3
1314

1415
__all__ = [
1516
'Default',
@@ -24,4 +25,5 @@
2425
'Switch',
2526
'WireguardPeers',
2627
'Wireless',
28+
'Mwan3',
2729
]
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from collections import OrderedDict
2+
3+
from ..schema import schema
4+
from .base import OpenWrtConverter
5+
6+
7+
class Mwan3(OpenWrtConverter):
8+
netjson_key = 'mwan3'
9+
intermediate_key = 'mwan3'
10+
_uci_types = ['interface']
11+
_schema = schema['properties']['mwan3']
12+
13+
def to_intermediate_loop(self, block, result, index=None):
14+
interfaces = self.__intermediate_interfaces(block.pop('interfaces', {}))
15+
result.setdefault('mwan3', [])
16+
result['mwan3'] = interfaces
17+
return result
18+
19+
def __intermediate_interfaces(self, interfaces):
20+
"""
21+
converts NetJSON interface to
22+
UCI intermediate data structure
23+
"""
24+
result = []
25+
for interface in interfaces:
26+
resultdict = OrderedDict((('.name', self._get_uci_name(interface.pop('name'))),
27+
('.type', 'interface')))
28+
resultdict.update(interface)
29+
result.append(resultdict)
30+
return result
31+
32+
def to_netjson_loop(self, block, result, index):
33+
result['mwan3'] = self.__netjson_mwan3(block)
34+
return result
35+
36+
def __netjson_mwan3(self, mwan3):
37+
del mwan3['.type']
38+
_name = mwan3.pop('.name')
39+
if _name != 'mwan3':
40+
mwan3['id'] = _name
41+
return self.type_cast(mwan3)

netjsonconfig/backends/openwrt/openwrt.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class OpenWrt(BaseBackend):
2525
converters.Wireless,
2626
converters.OpenVpn,
2727
converters.WireguardPeers,
28+
converters.Mwan3,
2829
converters.Default,
2930
]
3031
parser = OpenWrtParser

netjsonconfig/backends/openwrt/schema.py

Lines changed: 198 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -928,8 +928,204 @@
928928
},
929929
},
930930
},
931-
},
932-
},
931+
"mwan3": {
932+
"type": "object",
933+
"title": "Mwan3",
934+
"additionalProperties": True,
935+
"propertyOrder": 11,
936+
"properties": {
937+
"interfaces": {
938+
"type": "array",
939+
"title": "Interfaces",
940+
"propertyOrder": 1,
941+
"items": {
942+
"type": "object",
943+
"title": "Interface",
944+
"additionalProperties": True,
945+
"required": [
946+
"name",
947+
"track_ip",
948+
],
949+
"properties": {
950+
"name": {
951+
"type": "string",
952+
"title": "Name",
953+
"description": "the OpenWrt interface name",
954+
"propertyOrder": 1,
955+
},
956+
"enabled": {
957+
"type": "boolean",
958+
"title": "Enabled",
959+
"description": "specifies wether mwan3 should run on this interface",
960+
"default": False,
961+
"format": "checkbox",
962+
"propertyOrder": 2,
963+
},
964+
"track_method": {
965+
"type": "string",
966+
"title": "Tracking method",
967+
"description": "Tracking method for mwan3track",
968+
"enum": [
969+
"ping",
970+
"arping",
971+
"httping",
972+
"nping-*"
973+
],
974+
"default": "ping",
975+
"propertyOrder": 3,
976+
},
977+
"track_ip": {
978+
"title": "Tracking IPs",
979+
"description": "List of IPs to ping to test the interface. If this list "
980+
"is empty then the interface is always considered up",
981+
"type": "array",
982+
"uniqueItems": True,
983+
"additionalItems": True,
984+
"items": {
985+
"type": "string",
986+
"title": "ipv4 address",
987+
"minLength": 7,
988+
"maxLength": 15,
989+
"format": "ipv4"
990+
},
991+
"propertyOrder": 4,
992+
},
993+
"reliability": {
994+
"type": "integer",
995+
"title": "Reliability",
996+
"description": "Number of track_ip hosts that must reply for the test to"
997+
" be considered successful. Ensure there are at least this"
998+
" many track_ip hosts defined or the interface will always"
999+
" be considered down",
1000+
"default": 1,
1001+
"propertyOrder": 5,
1002+
},
1003+
"count": {
1004+
"type": "integer",
1005+
"title": "Count",
1006+
"description": "Number of checks to send to each host with each test",
1007+
"default": 1,
1008+
"propertyOrder": 6,
1009+
},
1010+
"timeout": {
1011+
"type": "integer",
1012+
"title": "Timeout",
1013+
"description": "Number of seconds to wait for an echo-reply after an "
1014+
"echo-request",
1015+
"default": 4,
1016+
"propertyOrder": 7,
1017+
},
1018+
"interval": {
1019+
"type": "integer",
1020+
"title": "Interval",
1021+
"description": "Number of seconds between each test",
1022+
"default": 10,
1023+
"propertyOrder": 8,
1024+
},
1025+
"failure_interval": {
1026+
"type": "integer",
1027+
"title": "Failure interval",
1028+
"description": "Number of seconds between each test during teardown on "
1029+
"failure detection",
1030+
"propertyOrder": 9,
1031+
},
1032+
"recovery_interval": {
1033+
"type": "integer",
1034+
"title": "Recovery interval",
1035+
"description": "Number of seconds between each test during tearup on "
1036+
"recovery detection",
1037+
"propertyOrder": 10,
1038+
},
1039+
"keep_failure_interval": {
1040+
"type": "boolean",
1041+
"title": "Keep failure interval",
1042+
"description": "In the event of an error, keep the number of seconds "
1043+
"between each test during teardown (failure detection)",
1044+
"default": False,
1045+
"format": "checkbox",
1046+
"propertyOrder": 11,
1047+
},
1048+
"up": {
1049+
"type": "integer",
1050+
"title": "Up",
1051+
"description": "Number of successful tests to consider link as alive",
1052+
"default": 5,
1053+
"propertyOrder": 12,
1054+
},
1055+
"down": {
1056+
"type": "integer",
1057+
"title": "Down",
1058+
"description": "Number of failed tests to consider link as dead",
1059+
"default": 5,
1060+
"propertyOrder": 13,
1061+
},
1062+
"family": {
1063+
"type": "string",
1064+
"title": "Family",
1065+
"description": "",
1066+
"enum": [
1067+
"ipv4",
1068+
"ipv6",
1069+
],
1070+
"default": "ipv4",
1071+
"propertyOrder": 14,
1072+
},
1073+
"max_ttl": {
1074+
"type": "integer",
1075+
"title": "Time to live",
1076+
"description": "Time to live (TTL) or hop limit. Only valid if tracking "
1077+
"method is ping.",
1078+
"default": 60,
1079+
"propertyOrder": 15,
1080+
},
1081+
"initial_state": {
1082+
"type": "string",
1083+
"title": "Initial state",
1084+
"description": "If the value is offline, then traffic goes via this "
1085+
"interface only if mwan3track checked the connection "
1086+
"first. If the value is online, then the mwan3track "
1087+
"test is not waited for. The interface is marked as "
1088+
"online at once.",
1089+
"enum": [
1090+
"online",
1091+
"offline",
1092+
],
1093+
"default": "online",
1094+
"propertyOrder": 16,
1095+
},
1096+
"size": {
1097+
"type": "integer",
1098+
"title": "Size",
1099+
"description": "Size of ping packets to use in bytes. Only valid if "
1100+
"tracking method is ping.",
1101+
"default": 56,
1102+
"propertyOrder": 17,
1103+
},
1104+
"flush_conntrack": {
1105+
"title": "Flush connection tracking",
1106+
"description": "specifies upon which events the connections table should"
1107+
" be flushed",
1108+
"type": "array",
1109+
"uniqueItems": True,
1110+
"additionalItems": True,
1111+
"items": {
1112+
"type": "string",
1113+
"enum": [
1114+
"ifup",
1115+
"ifdown",
1116+
"connected",
1117+
"disconnected",
1118+
],
1119+
},
1120+
"propertyOrder": 18,
1121+
},
1122+
}
1123+
}
1124+
}
1125+
}
1126+
}
1127+
}
1128+
}
9331129
)
9341130

9351131
# add OpenVPN schema

0 commit comments

Comments
 (0)