Skip to content

Commit

Permalink
Initial work on ground routing
Browse files Browse the repository at this point in the history
  • Loading branch information
G10h4ck committed Dec 25, 2014
1 parent 0fa6b97 commit cb034ba
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 0 deletions.
40 changes: 40 additions & 0 deletions packages/lime-hwd-ground-routing/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#
# Copyright (C) 2006-2014 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v3.
#

include $(TOPDIR)/rules.mk

LIME_BUILDDATE:=$(shell date +%Y%m%d_%H%M)
LIME_CODENAME:=bigbang

GIT_COMMIT_DATE:=$(shell git log -n 1 --pretty=%ad --date=short . )
GIT_COMMIT_TSTAMP:=$(shell git log -n 1 --pretty=%at . )

PKG_NAME:=lime-hwd-ground-routing
PKG_VERSION=$(GIT_COMMIT_DATE)-$(GIT_COMMIT_TSTAMP)

include $(INCLUDE_DIR)/package.mk

define Package/$(PKG_NAME)
TITLE:=Manage 802.1q VLANs for ground routing
CATEGORY:=LiMe
URL:=http://libre-mesh.org
DEPENDS:=+lime-system +lua +libuci-lua
endef

define Build/Compile
@rm -rf ./build || true
@cp -r ./src ./build
@sed -i '/^\s*--!.*/d' build/*.lua || true
@sed -i '/^\s*#\[Doc\]/d' build/*.sh || true
endef

define Package/$(PKG_NAME)/install
@mkdir -p $(1)/usr/lib/lua/lime/hwd || true
$(CP) ./build/ground_routing.lua $(1)/usr/lib/lua/lime/hwd/ground_routing.lua
@chmod +x $(1)/usr/lib/lua/lime/hwd/ground_routing.lua
endef

$(eval $(call BuildPackage,$(PKG_NAME)))
61 changes: 61 additions & 0 deletions packages/lime-hwd-ground-routing/src/ground_routing.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/lua

local libuci = require("uci")
local hardware_detection = require("lime.hardware_detection")
local config = require("lime.config")
local utils = require("lime.utils")

local ground_routing = {}

ground_routing.sectionNamePrefix = hardware_detection.sectionNamePrefix.."ground_routing_"

function ground_routing.clean()
function cleanGrSection(section)
local sectionName = section[".name"]
local isGr = utils.stringStarts(sectionName, ground_routing.sectionNamePrefix)
local autogenerated = config.autogenerable(sectionName)

if ( isGr and autogenerated ) then config.delete(section[".name"]) end
end

config.foreach("net", cleanGrSection)

local uci = libuci:cursor()
uci:foreach("network", "switch_vlan", cleanGrSection)
end

function ground_routing.detect_hardware()
function parse_gr(section)
local vlan = section["vlan"]
local switchName = section["switch"]

if switchName then
local secname = ground_routing.sectionNamePrefix.."network_"..section[".name"].."_"..switchName.."_"..vlan
local ports = ""
for _,p in pairs(section["switch_ports"]) do ports = ports..p.."t " end

local uci = libuci:cursor()
uci:set("network", secname, "switch_vlan")
uci:set("network", secname, "device", switchName)
uci:set("network", secname, "vlan", vlan)
uci:set("network", secname, "ports", ports)
uci:save("network")
end

local basedev = section["basedev"]
if basedev then
local secname = ground_routing.sectionNamePrefix.."network_"..section[".name"].."_"..basedev.."_"..vlan

local uci = libuci:cursor()
uci:set("network", secname, "device")
uci:set("network", secname, "type", "8021q")
uci:set("network", secname, "name", basedev.."."..vlan)
uci:set("network", secname, "vid", vlan)
uci:save("network")
end
end

config.foreach("hwd_gr", parse_gr)
end

return ground_routing
1 change: 1 addition & 0 deletions packages/lime-hwd-openwrt-wan/src/openwrt_wan.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

local libuci = require("uci")
local hardware_detection = require("lime.hardware_detection")
local config = require("lime.config")

local openwrt_wan = {}

Expand Down
10 changes: 10 additions & 0 deletions packages/lime-system/files/etc/config/lime
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,13 @@

#config net eth5
# list protocols 'manual'


### Ground routing specific sections

#config hwd_gr link1
# option basedev 'eth0'
# option switch 'switch0'
# list switch_ports '0'
# list switch_ports '4'
# option vlan '173'

0 comments on commit cb034ba

Please sign in to comment.