Remove simulator code
It's now a separate project: https://github.com/zaidka/genieacs-sim
This commit is contained in:
1 parent
595c318720
commit
1e9aff2fdc
4 files changed
-1402
No files matched your search
@@ -1,72 +0,0 @@
|
|||||||
###
|
|
||||||
# Copyright 2013, 2014, 2015 Zaid Abdulla
|
|
||||||
#
|
|
||||||
# GenieACS is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU Affero General Public License as
|
|
||||||
# published by the Free Software Foundation, either version 3 of the
|
|
||||||
# License, or (at your option) any later version.
|
|
||||||
#
|
|
||||||
# GenieACS is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU Affero General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
|
||||||
# along with GenieACS. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
###
|
|
||||||
|
|
||||||
db = require '../lib/db'
|
|
||||||
fs = require 'fs'
|
|
||||||
|
|
||||||
deviceJson = {}
|
|
||||||
|
|
||||||
f = (object, path) ->
|
|
||||||
if (not path)
|
|
||||||
path = ''
|
|
||||||
|
|
||||||
for key in Object.keys(object)
|
|
||||||
continue if key[0] == '_'
|
|
||||||
|
|
||||||
if (object[key])
|
|
||||||
isObject = '_object' of object[key] or '_instance' of object[key]
|
|
||||||
isValue = '_value' of object[key]
|
|
||||||
if (isObject and isValue) or (not isObject and not isValue)
|
|
||||||
throw new Error('Unexpected object')
|
|
||||||
|
|
||||||
if (isValue)
|
|
||||||
value = object[key]['_value']
|
|
||||||
if (typeof value == 'boolean')
|
|
||||||
if (value)
|
|
||||||
value = 1
|
|
||||||
else
|
|
||||||
value = 0
|
|
||||||
|
|
||||||
values = [object[key]['_writable'] or false, value.toString()]
|
|
||||||
values.push(object[key]['_type']) if (object[key]['_type'])
|
|
||||||
deviceJson["#{path}#{key}"] = values
|
|
||||||
continue
|
|
||||||
|
|
||||||
if (isObject)
|
|
||||||
values = [object[key]['_writable'] or false]
|
|
||||||
deviceJson["#{path}#{key}."] = values
|
|
||||||
f(object[key], "#{path}#{key}.")
|
|
||||||
|
|
||||||
|
|
||||||
db.connect((err) ->
|
|
||||||
throw err if (err)
|
|
||||||
|
|
||||||
db.devicesCollection.findOne({_id: process.argv[2]}, {}, (err, device) ->
|
|
||||||
throw err if (err)
|
|
||||||
|
|
||||||
if (not device)
|
|
||||||
throw new Error('Device not found')
|
|
||||||
|
|
||||||
f(device)
|
|
||||||
fs.writeFile("data_model_#{process.argv[2]}.json", JSON.stringify(deviceJson, null, ' '), () ->
|
|
||||||
throw err if (err)
|
|
||||||
|
|
||||||
console.log("data_model_#{process.argv[2]}.json Saved")
|
|
||||||
process.exit(0)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -1,153 +0,0 @@
|
|||||||
###
|
|
||||||
# Copyright 2013, 2014 Zaid Abdulla
|
|
||||||
#
|
|
||||||
# GenieACS is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU Affero General Public License as
|
|
||||||
# published by the Free Software Foundation, either version 3 of the
|
|
||||||
# License, or (at your option) any later version.
|
|
||||||
#
|
|
||||||
# GenieACS is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU Affero General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
|
||||||
# along with GenieACS. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
###
|
|
||||||
|
|
||||||
NAMESPACES = {
|
|
||||||
'soap-enc' : 'http://schemas.xmlsoap.org/soap/encoding/',
|
|
||||||
'soap-env' : 'http://schemas.xmlsoap.org/soap/envelope/',
|
|
||||||
'xsd' : 'http://www.w3.org/2001/XMLSchema',
|
|
||||||
'xsi' : 'http://www.w3.org/2001/XMLSchema-instance',
|
|
||||||
'cwmp' : 'urn:dslforum-org:cwmp-1-0',
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
exports.inform = (device, xmlOut, callback) ->
|
|
||||||
body = xmlOut.root().childNodes()[1]
|
|
||||||
inform = body.node('cwmp:Inform')
|
|
||||||
|
|
||||||
deviceId = inform.node('DeviceId')
|
|
||||||
deviceId.node('Manufacturer', device['InternetGatewayDevice.DeviceInfo.Manufacturer'][1])
|
|
||||||
deviceId.node('OUI', device['InternetGatewayDevice.DeviceInfo.ManufacturerOUI'][1])
|
|
||||||
deviceId.node('ProductClass', device['InternetGatewayDevice.DeviceInfo.ProductClass'][1])
|
|
||||||
deviceId.node('SerialNumber', device['InternetGatewayDevice.DeviceInfo.SerialNumber'][1])
|
|
||||||
|
|
||||||
eventStruct = inform.node('Event').attr({'soap-enc:arrayType' : 'cwmp:EventStruct[1]'}).node('EventStruct')
|
|
||||||
eventStruct.node('EventCode', '2 PERIODIC')
|
|
||||||
eventStruct.node('CommandKey')
|
|
||||||
|
|
||||||
inform.node('MaxEnvelopes', '1')
|
|
||||||
inform.node('CurrentTime', new Date().toISOString())
|
|
||||||
inform.node('RetryCount', '0')
|
|
||||||
|
|
||||||
parameterList = inform.node('ParameterList').attr({'soap-enc:arrayType' : 'cwmp:ParameterValueStruct[7]'})
|
|
||||||
for p in [
|
|
||||||
'InternetGatewayDevice.DeviceInfo.SpecVersion',
|
|
||||||
'InternetGatewayDevice.DeviceInfo.HardwareVersion',
|
|
||||||
'InternetGatewayDevice.DeviceInfo.SoftwareVersion',
|
|
||||||
'InternetGatewayDevice.DeviceInfo.ProvisioningCode',
|
|
||||||
'InternetGatewayDevice.ManagementServer.ParameterKey',
|
|
||||||
'InternetGatewayDevice.ManagementServer.ConnectionRequestURL',
|
|
||||||
'InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.ExternalIPAddress']
|
|
||||||
parameterValueStruct = parameterList.node('ParameterValueStruct')
|
|
||||||
parameterValueStruct.node('Name', p)
|
|
||||||
parameterValueStruct.node('Value', device[p][1]).attr({'xsi:type' : "#{device[p][2]}"})
|
|
||||||
|
|
||||||
callback(xmlOut)
|
|
||||||
|
|
||||||
|
|
||||||
exports.GetParameterNames = (device, xmlIn, xmlOut, callback) ->
|
|
||||||
parameterNames = Object.keys(device).sort()
|
|
||||||
parameterPath = xmlIn.get('/soap-env:Envelope/soap-env:Body/cwmp:GetParameterNames/ParameterPath', NAMESPACES).text()
|
|
||||||
nextLevel = !!eval(xmlIn.get('/soap-env:Envelope/soap-env:Body/cwmp:GetParameterNames/NextLevel', NAMESPACES).text())
|
|
||||||
|
|
||||||
parameterList = []
|
|
||||||
if nextLevel
|
|
||||||
for p in parameterNames
|
|
||||||
if p.startsWith(parameterPath) and p.length > parameterPath.length + 1
|
|
||||||
i = p.indexOf('.', parameterPath.length + 1)
|
|
||||||
if i == -1 or i == p.length - 1
|
|
||||||
parameterList.push(p)
|
|
||||||
else
|
|
||||||
for p in parameterNames
|
|
||||||
if p.startsWith(parameterPath)
|
|
||||||
parameterList.push(p)
|
|
||||||
|
|
||||||
getParameterNamesResponseNode = xmlOut.root().childNodes()[1].node('cwmp:GetParameterNamesResponse')
|
|
||||||
parameterListNode = getParameterNamesResponseNode.node('ParameterList')
|
|
||||||
parameterListNode.attr({'soap-enc:arrayType' : "cwmp:ParameterInfoStruct[#{parameterList.length}]"})
|
|
||||||
for p in parameterList
|
|
||||||
parameterInfoStructNode = parameterListNode.node('ParameterInfoStruct')
|
|
||||||
parameterInfoStructNode.node('Name', p)
|
|
||||||
parameterInfoStructNode.node('Writable', String(device[p][0]))
|
|
||||||
|
|
||||||
callback(xmlOut)
|
|
||||||
|
|
||||||
|
|
||||||
exports.GetParameterValues = (device, xmlIn, xmlOut, callback) ->
|
|
||||||
parameterNames = xmlIn.find('/soap-env:Envelope/soap-env:Body/cwmp:GetParameterValues/ParameterNames/*', NAMESPACES)
|
|
||||||
|
|
||||||
parameterList = xmlOut.root().childNodes()[1].node('cwmp:GetParameterValuesResponse').node('ParameterList')
|
|
||||||
parameterList.attr({'soap-enc:arrayType' : "cwmp:ParameterValueStruct[#{parameterNames.length}]"})
|
|
||||||
|
|
||||||
for p in parameterNames
|
|
||||||
name = p.text()
|
|
||||||
value = device[name][1]
|
|
||||||
type = device[name][2]
|
|
||||||
valueStruct = parameterList.node('ParameterValueStruct')
|
|
||||||
valueStruct.node('Name', name)
|
|
||||||
valueStruct.node('Value', device[name][1]).attr({'xsi:type' : "#{type}"})
|
|
||||||
|
|
||||||
callback(xmlOut)
|
|
||||||
|
|
||||||
|
|
||||||
exports.SetParameterValues = (device, xmlIn, xmlOut, callback) ->
|
|
||||||
parameterValues = xmlIn.find('/soap-env:Envelope/soap-env:Body/cwmp:SetParameterValues/ParameterList/*', NAMESPACES)
|
|
||||||
|
|
||||||
for p in parameterValues
|
|
||||||
name = p.get('Name').text()
|
|
||||||
value = p.get('Value')
|
|
||||||
device[name][1] = value.text()
|
|
||||||
device[name][2] = value.attr('type').value()
|
|
||||||
|
|
||||||
responseNode = xmlOut.root().childNodes()[1].node('cwmp:SetParameterValuesResponse')
|
|
||||||
responseNode.node('Status', '0')
|
|
||||||
|
|
||||||
callback(xmlOut)
|
|
||||||
|
|
||||||
|
|
||||||
exports.AddObject = (device, xmlIn, xmlOut, callback) ->
|
|
||||||
objectName = xmlIn.get('/soap-env:Envelope/soap-env:Body/cwmp:AddObject/ObjectName', NAMESPACES).text()
|
|
||||||
|
|
||||||
parameters = []
|
|
||||||
instances = {}
|
|
||||||
instanceNumber = 1
|
|
||||||
while device[objectName + instanceNumber + '.']?
|
|
||||||
instanceNumber += 1
|
|
||||||
|
|
||||||
for p in Object.keys(device).sort()
|
|
||||||
if p.startsWith(objectName) and p.length > objectName.length
|
|
||||||
n = objectName + instanceNumber + p.slice(p.indexOf('.', objectName.length))
|
|
||||||
if not device[n]?
|
|
||||||
device[n] = [device[p][0], '', device[p][2]]
|
|
||||||
|
|
||||||
responseNode = xmlOut.root().childNodes()[1].node('cwmp:AddObjectResponse')
|
|
||||||
responseNode.node('InstanceNumber', String(instanceNumber))
|
|
||||||
responseNode.node('Status', '0')
|
|
||||||
|
|
||||||
callback(xmlOut)
|
|
||||||
|
|
||||||
|
|
||||||
exports.DeleteObject = (device, xmlIn, xmlOut, callback) ->
|
|
||||||
objectName = xmlIn.get('/soap-env:Envelope/soap-env:Body/cwmp:DeleteObject/ObjectName', NAMESPACES).text()
|
|
||||||
|
|
||||||
for p in Object.keys(device)
|
|
||||||
if p.startsWith(objectName)
|
|
||||||
delete device[p]
|
|
||||||
|
|
||||||
responseNode = xmlOut.root().childNodes()[1].node('cwmp:DeleteObjectResponse')
|
|
||||||
responseNode.node('Status', '0')
|
|
||||||
|
|
||||||
callback(xmlOut)
|
|
||||||
@@ -1,173 +0,0 @@
|
|||||||
###
|
|
||||||
# Copyright 2013, 2014 Zaid Abdulla
|
|
||||||
#
|
|
||||||
# GenieACS is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU Affero General Public License as
|
|
||||||
# published by the Free Software Foundation, either version 3 of the
|
|
||||||
# License, or (at your option) any later version.
|
|
||||||
#
|
|
||||||
# GenieACS is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU Affero General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
|
||||||
# along with GenieACS. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
###
|
|
||||||
|
|
||||||
http = require 'http'
|
|
||||||
libxmljs = require 'libxmljs'
|
|
||||||
deviceTemplate = require './huawei_bm632w'
|
|
||||||
methods = require './methods'
|
|
||||||
util = require 'util'
|
|
||||||
|
|
||||||
NAMESPACES = {
|
|
||||||
'soap-enc' : 'http://schemas.xmlsoap.org/soap/encoding/',
|
|
||||||
'soap-env' : 'http://schemas.xmlsoap.org/soap/envelope/',
|
|
||||||
'xsd' : 'http://www.w3.org/2001/XMLSchema',
|
|
||||||
'xsi' : 'http://www.w3.org/2001/XMLSchema-instance',
|
|
||||||
'cwmp' : 'urn:dslforum-org:cwmp-1-0',
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
createSoapDocument = (id) ->
|
|
||||||
xml = libxmljs.Document()
|
|
||||||
env = xml.node('soap-env:Envelope')
|
|
||||||
for prefix, url of NAMESPACES
|
|
||||||
env.defineNamespace prefix, url
|
|
||||||
|
|
||||||
header = env.node('soap-env:Header')
|
|
||||||
header.node('cwmp:ID').attr({'soap-env:mustUnderstand' : 1}).text(id)
|
|
||||||
body = env.node('soap-env:Body')
|
|
||||||
return xml
|
|
||||||
|
|
||||||
|
|
||||||
createDevice = (serial) ->
|
|
||||||
device = JSON.parse(JSON.stringify(deviceTemplate))
|
|
||||||
device['InternetGatewayDevice.DeviceInfo.SerialNumber'][1] = serial
|
|
||||||
return device
|
|
||||||
|
|
||||||
|
|
||||||
sendRequest = (device,xml, callback) ->
|
|
||||||
headers = {}
|
|
||||||
if xml?
|
|
||||||
body = xml.toString()
|
|
||||||
else
|
|
||||||
body = ''
|
|
||||||
|
|
||||||
headers['Content-Length'] = body.length
|
|
||||||
headers['Content-Type'] = 'text/xml; charset="utf-8"'
|
|
||||||
|
|
||||||
if device.Cookies?
|
|
||||||
headers['Cookie'] = device['Cookies']
|
|
||||||
|
|
||||||
options = {
|
|
||||||
hostname: 'localhost',
|
|
||||||
port: 7547,
|
|
||||||
path: '/',
|
|
||||||
method: 'POST',
|
|
||||||
headers: headers
|
|
||||||
}
|
|
||||||
|
|
||||||
request = http.request(options, (response) ->
|
|
||||||
chunks = []
|
|
||||||
bytes = 0
|
|
||||||
response.on('data', (chunk) ->
|
|
||||||
chunks.push(chunk)
|
|
||||||
bytes += chunk.length
|
|
||||||
)
|
|
||||||
response.on('end', () ->
|
|
||||||
body = new Buffer(bytes)
|
|
||||||
offset = 0
|
|
||||||
chunks.forEach((chunk) ->
|
|
||||||
chunk.copy(body, offset, 0, chunk.length)
|
|
||||||
offset += chunk.length
|
|
||||||
)
|
|
||||||
|
|
||||||
if +response.headers['Content-Length'] > 0 or body.length > 0
|
|
||||||
xml = libxmljs.parseXml(body)
|
|
||||||
else
|
|
||||||
xml = null
|
|
||||||
|
|
||||||
if response.headers['set-cookie']?
|
|
||||||
# TODO set individual cookies
|
|
||||||
device['Cookies'] = [true, response.headers['set-cookie'], 'xsd:string']
|
|
||||||
|
|
||||||
callback(xml)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
request.end(body)
|
|
||||||
|
|
||||||
|
|
||||||
startSession = (device) ->
|
|
||||||
xmlOut = createSoapDocument(0)
|
|
||||||
methods.inform(device, xmlOut, (xml) ->
|
|
||||||
sendRequest(device, xml, (xml) ->
|
|
||||||
if not xml?
|
|
||||||
console.log('No inform response, trying again in 10 seconds.')
|
|
||||||
setTimeout(() ->
|
|
||||||
startSession(device)
|
|
||||||
, 10000)
|
|
||||||
return
|
|
||||||
sendRequest(device, null, (xml) ->
|
|
||||||
handleMethod(device, xml)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
createFaultResponse = (xmlOut, code, message) ->
|
|
||||||
body = xmlOut.root().childNodes()[1]
|
|
||||||
|
|
||||||
soapFault = body.node('soap-env:Fault')
|
|
||||||
soapFault.node('faultcode').text('Client')
|
|
||||||
soapFault.node('faultstring').text('CWMP fault')
|
|
||||||
|
|
||||||
fault = soapFault.node('detail').node('cwmp:Fault')
|
|
||||||
fault.node('FaultCode').text(code)
|
|
||||||
fault.node('FaultString').text(message)
|
|
||||||
|
|
||||||
|
|
||||||
handleMethod = (device, xml) ->
|
|
||||||
if not xml?
|
|
||||||
setTimeout(() ->
|
|
||||||
startSession(device)
|
|
||||||
, 1000 * parseInt(device['InternetGatewayDevice.ManagementServer.PeriodicInformInterval'][1]))
|
|
||||||
return
|
|
||||||
|
|
||||||
requestId = xml.get('/soap-env:Envelope/soap-env:Header/cwmp:ID', NAMESPACES).text()
|
|
||||||
|
|
||||||
xmlOut = createSoapDocument(requestId)
|
|
||||||
|
|
||||||
element = xml.get('/soap-env:Envelope/soap-env:Body/cwmp:*', NAMESPACES)
|
|
||||||
method = methods[element.name()]
|
|
||||||
|
|
||||||
if method?
|
|
||||||
methods[element.name()](device, xml, xmlOut, (xml) ->
|
|
||||||
sendRequest(device, xml, (xml) ->
|
|
||||||
handleMethod(device, xml)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
else
|
|
||||||
createFaultResponse(xmlOut, 9000, 'Method not supported')
|
|
||||||
sendRequest(device, xmlOut, (xml) ->
|
|
||||||
handleMethod(device, xml)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
cluster = require 'cluster'
|
|
||||||
|
|
||||||
NUM_WORKERS = 1
|
|
||||||
NUM_DEVICES = 1
|
|
||||||
|
|
||||||
if cluster.isMaster
|
|
||||||
for i in [0 ... NUM_WORKERS]
|
|
||||||
cluster.fork({SERIAL_PREFIX : i})
|
|
||||||
else
|
|
||||||
for i in [0...NUM_DEVICES]
|
|
||||||
serial = process.env.SERIAL_PREFIX + ("00000#{i}".slice(-6))
|
|
||||||
device = createDevice(serial)
|
|
||||||
do (device) ->
|
|
||||||
setTimeout(() ->
|
|
||||||
startSession(device)
|
|
||||||
, i * 100)
|
|
||||||
Reference in new issue
Block a user