Class: Cwmp::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/cwmp/message.rb

Constant Summary collapse

NAMESPACES =
{"xmlns:soap" => "http://schemas.xmlsoap.org/soap/envelope/", "xmlns:soap-enc" => "http://schemas.xmlsoap.org/soap/encoding/", "xmlns:cwmp" => "urn:dslforum-org:cwmp-1-0", "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance", "xml:xsd" => "http://www.w3.org/2001/XMLSchema", "xmlns" => "urn:dslforum-org:cwmp-1-0"}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#message_typeObject

Returns the value of attribute message_type.



7
8
9
# File 'lib/cwmp/message.rb', line 7

def message_type
  @message_type
end

#parsed_xml_docObject

Returns the value of attribute parsed_xml_doc.



7
8
9
# File 'lib/cwmp/message.rb', line 7

def parsed_xml_doc
  @parsed_xml_doc
end

#raw_xml_messageObject

Returns the value of attribute raw_xml_message.



7
8
9
# File 'lib/cwmp/message.rb', line 7

def raw_xml_message
  @raw_xml_message
end

Class Method Details

.change_du_state_responseObject



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/cwmp/message.rb', line 156

def self.change_du_state_response
    m = Cwmp::Message.new

    m.message_type = "ChangeDUStateResponse"

    b = Nokogiri::XML::Builder.new

    b[:soap].Envelope(NAMESPACES) {
        b[:soap].Header {}
        b[:soap].Body {
            b[:cwmp].ChangeDUStateResponse() {}
        }
    }

    m.raw_xml_message = b.to_xml

    return m
end

.get_parameter_names_responseObject



230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
# File 'lib/cwmp/message.rb', line 230

def self.get_parameter_names_response
    m = Cwmp::Message.new

    m.message_type = "Inform"
    m.raw_xml_message = '<soap:Envelope
	xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
	xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/"
	xmlns:cwmp="urn:dslforum-org:cwmp-1-0"
	xmlns:xsd="http://www.w3.org/2001/XMLSchema"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Header>
	<cwmp:ID soap:mustUnderstand="1"></cwmp:ID>
</soap:Header>
<soap:Body>
<cwmp:GetParameterNamesResponse>
<ParameterList soap-enc:arrayType="cwmp:ParameterInfoStruct[17]">
<ParameterInfoStruct>
	<Name>InternetGatewayDevice.LANDeviceNumberOfEntries</Name>
	<Writable>0</Writable>
</ParameterInfoStruct>
<ParameterInfoStruct>
	<Name>InternetGatewayDevice.WANDeviceNumberOfEntries</Name>
	<Writable>0</Writable>
</ParameterInfoStruct>
<ParameterInfoStruct>
	<Name>InternetGatewayDevice.DeviceInfo.</Name>
	<Writable>0</Writable>
</ParameterInfoStruct>
<ParameterInfoStruct>
	<Name>InternetGatewayDevice.ManagementServer.</Name>
	<Writable>0</Writable>
</ParameterInfoStruct>
<ParameterInfoStruct>
	<Name>InternetGatewayDevice.Time.</Name>
	<Writable>0</Writable>
</ParameterInfoStruct>
<ParameterInfoStruct>
	<Name>InternetGatewayDevice.Layer3Forwarding.</Name>
	<Writable>0</Writable>
</ParameterInfoStruct>
<ParameterInfoStruct>
	<Name>InternetGatewayDevice.LANDevice.</Name>
	<Writable>0</Writable>
</ParameterInfoStruct>
<ParameterInfoStruct>
	<Name>InternetGatewayDevice.WANDevice.</Name>
	<Writable>0</Writable>
</ParameterInfoStruct>
<ParameterInfoStruct>
	<Name>InternetGatewayDevice.X_00507F_InternetAcc.</Name>
	<Writable>0</Writable>
</ParameterInfoStruct>
<ParameterInfoStruct>
	<Name>InternetGatewayDevice.X_00507F_LAN.</Name>
	<Writable>0</Writable>
</ParameterInfoStruct>
<ParameterInfoStruct>
	<Name>InternetGatewayDevice.X_00507F_NAT.</Name>
	<Writable>0</Writable>
</ParameterInfoStruct>
<ParameterInfoStruct>
	<Name>InternetGatewayDevice.X_00507F_VLAN.</Name>
	<Writable>0</Writable>
</ParameterInfoStruct>
<ParameterInfoStruct>
	<Name>InternetGatewayDevice.X_00507F_Firewall.</Name>
	<Writable>0</Writable>
</ParameterInfoStruct>
<ParameterInfoStruct>
	<Name>InternetGatewayDevice.X_00507F_Applications.</Name>
	<Writable>0</Writable>
</ParameterInfoStruct>
<ParameterInfoStruct>
	<Name>InternetGatewayDevice.X_00507F_System.</Name>
	<Writable>0</Writable>
</ParameterInfoStruct>
<ParameterInfoStruct>
	<Name>InternetGatewayDevice.X_00507F_Status.</Name>
	<Writable>0</Writable>
</ParameterInfoStruct>
<ParameterInfoStruct>
	<Name>InternetGatewayDevice.X_00507F_Diagnostics.</Name>
	<Writable>0</Writable>
</ParameterInfoStruct>
</ParameterList>
</cwmp:GetParameterNamesResponse>
</soap:Body>
</soap:Envelope>'

    return m
end

.get_parameter_values(leaves) ⇒ Object



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/cwmp/message.rb', line 206

def self.get_parameter_values(leaves)
    b = Nokogiri::XML::Builder.new

    b[:soap].Envelope(NAMESPACES) {
        b[:soap].Header {}
        b[:soap].Body {

            b[:cwmp].GetParameterValues() {
                b.ParameterNames({"soap-enc:arrayType" => "cwmp:string[#{leaves.kind_of?(Array) ? leaves.size : '1'}]"}) {
                    if leaves.kind_of?(Array)
                        leaves.each do |leaf|
                            b.string leaf
                        end
                    else
                        b.string leaves
                    end
                }
            }
        }
    }

    return b.to_xml
end

.get_parameter_values_responseObject



322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
# File 'lib/cwmp/message.rb', line 322

def self.get_parameter_values_response
    m = Cwmp::Message.new

    m.message_type = "Inform"
    m.raw_xml_message = '<soap:Envelope
	xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
	xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/"
	xmlns:cwmp="urn:dslforum-org:cwmp-1-0"
	xmlns:xsd="http://www.w3.org/2001/XMLSchema"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Header>
	<cwmp:ID soap:mustUnderstand="1"></cwmp:ID>
</soap:Header>
<soap:Body>
<cwmp:GetParameterValuesResponse>
<ParameterList soap-enc:arrayType="cwmp:ParameterValueStruct[5]">
<ParameterValueStruct>
	<Name>InternetGatewayDevice.Time.NTPServer1</Name>
	<Value xsi:type="xsd:string">pool.ntp.org</Value>
</ParameterValueStruct>
<ParameterValueStruct>
	<Name>InternetGatewayDevice.Time.CurrentLocalTime</Name>
	<Value xsi:type="xsd:dateTime">2014-07-11T09:08:25</Value>
</ParameterValueStruct>
<ParameterValueStruct>
	<Name>InternetGatewayDevice.Time.LocalTimeZone</Name>
	<Value xsi:type="xsd:string">+00:00</Value>
</ParameterValueStruct>
<ParameterValueStruct>
	<Name>InternetGatewayDevice.Time.LocalTimeZoneName</Name>
	<Value xsi:type="xsd:string">Greenwich Mean Time : Dublin</Value>
</ParameterValueStruct>
<ParameterValueStruct>
	<Name>InternetGatewayDevice.Time.DaylightSavingsUsed</Name>
	<Value xsi:type="xsd:boolean">0</Value>
</ParameterValueStruct>
</ParameterList>
</cwmp:GetParameterValuesResponse>
</soap:Body>
</soap:Envelope>'

    return m
end

.inform(manufacturer, oui, serial, eventcodes, software_version) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/cwmp/message.rb', line 71

def self.inform(manufacturer, oui, serial, eventcodes, software_version)
    m = Cwmp::Message.new
puts "here we go"
    m.message_type = "Inform"
    m.raw_xml_message = '<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
       xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:cwmp="urn:dslforum-org:cwmp-1-0"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Header>
<cwmp:ID soap:mustUnderstand="1">37</cwmp:ID>
    </soap:Header>
    <soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<cwmp:Inform>
    <DeviceId>
        <Manufacturer>'+manufacturer+'</Manufacturer>
        <OUI>'+oui+'</OUI>
        <ProductClass>Router</ProductClass>
        <SerialNumber>'+serial+'</SerialNumber>
    </DeviceId>
    <Event>
        <EventStruct>
            <EventCode>'+eventcodes+'</EventCode>
            <CommandKey/>
        </EventStruct>
    </Event>
    <MaxEnvelopes>1</MaxEnvelopes>
    <CurrentTime>2003-01-01T05:36:55Z</CurrentTime>
    <RetryCount>0</RetryCount>
    <ParameterList soap-enc:arrayType="cwmp:ParameterValueStruct[7]">
        <ParameterValueStruct xsi:type="cwmp:ParameterValueStruct">
            <Name>InternetGatewayDevice.DeviceInfo.HardwareVersion</Name>
            <Value xsi:type="xsd:string">MNR001</Value>
        </ParameterValueStruct>
        <ParameterValueStruct xsi:type="cwmp:ParameterValueStruct">
            <Name>InternetGatewayDevice.DeviceInfo.ProvisioningCode</Name>
            <Value xsi:type="xsd:string">ABCD</Value>
        </ParameterValueStruct>
        <ParameterValueStruct xsi:type="cwmp:ParameterValueStruct">
            <Name>InternetGatewayDevice.DeviceInfo.SoftwareVersion</Name>
            <Value xsi:type="xsd:string">'+software_version+'</Value>
        </ParameterValueStruct>
        <ParameterValueStruct xsi:type="cwmp:ParameterValueStruct">
            <Name>InternetGatewayDevice.DeviceInfo.SpecVersion</Name>
            <Value xsi:type="xsd:string">1.0</Value>
        </ParameterValueStruct>
        <ParameterValueStruct xsi:type="cwmp:ParameterValueStruct">
            <Name>InternetGatewayDevice.ManagementServer.ConnectionRequestURL</Name>
            <Value xsi:type="xsd:string">http://127.0.0.1:9600/'+serial+'</Value>
        </ParameterValueStruct>
        <ParameterValueStruct xsi:type="cwmp:ParameterValueStruct">
            <Name>InternetGatewayDevice.ManagementServer.ParameterKey</Name>
            <Value xsi:type="xsd:string"/>
        </ParameterValueStruct>
        <ParameterValueStruct xsi:type="cwmp:ParameterValueStruct">
            <Name>InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.ExternalIPAddress
            </Name>
            <Value xsi:type="xsd:string">10.19.0.'+serial+'</Value>
        </ParameterValueStruct>
    </ParameterList>
</cwmp:Inform>
    </soap:Body>
</soap:Envelope>'

    return m
end

.inform_responseObject



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/cwmp/message.rb', line 137

def self.inform_response
    m = Cwmp::Message.new

    m.message_type = "InformResponse"

    b = Nokogiri::XML::Builder.new

    b[:soap].Envelope(NAMESPACES) {
        b[:soap].Header {}
        b[:soap].Body {
            b[:cwmp].InformResponse() {}
        }
    }

    m.raw_xml_message = b.to_xml

    return m
end

.parse_from_text(txtmsg) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/cwmp/message.rb', line 9

def self.parse_from_text txtmsg
    doc = Nokogiri::XML(txtmsg)
    txtmsg =~ /(\w+):Envelope/
    soap_ns = $1
    message_type = doc.css("#{soap_ns}|Body")[0].element_children[0].name

    m = Cwmp::Message.new
    m.message_type = message_type
    m.parsed_xml_doc = doc
    m.raw_xml_message = txtmsg
    return m
end

.rebootObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/cwmp/message.rb', line 39

def self.reboot
    m = Cwmp::Message.new
    m.message_type = "Reboot"
    b = Nokogiri::XML::Builder.new

    b[:soap].Envelope(NAMESPACES) {
        b[:soap].Header {}
        b[:soap].Body {
            b[:cwmp].Reboot() {}
        }
    }

    m.raw_xml_message = b.to_xml
    return m
end

.reboot_responseObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/cwmp/message.rb', line 55

def self.reboot_response
    m = Cwmp::Message.new
    m.message_type = "RebootResponse"
    b = Nokogiri::XML::Builder.new

    b[:soap].Envelope(NAMESPACES) {
        b[:soap].Header {}
        b[:soap].Body {
            b[:cwmp].RebootResponse() {}
        }
    }

    m.raw_xml_message = b.to_xml
    return m
end

.set_parameter_values(leaves) ⇒ Object



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/cwmp/message.rb', line 175

def self.set_parameter_values(leaves)
    b = Nokogiri::XML::Builder.new

    b[:soap].Envelope(NAMESPACES) {
        b[:soap].Header {}
        b[:soap].Body {

            b[:cwmp].SetParameterValues() {
                b.ParameterList({"soap-enc:arrayType" => "cwmp:ParameterValueStruct[#{leaves[0].kind_of?(Array) ? leaves.size : '1'}]"}) {
                    if leaves[0].kind_of?(Array)
                        leaves.each do |leaf|
                            b.ParameterValueStruct {
                                b.Name leaf[0]
                                b.Value leaf[1]
                            }
                        end
                    else
                        b.ParameterValueStruct {
                            b.Name leaves[0]
                            b.Value leaves[1]
                        }
                    end
                    b.ParameterKey "asdads"
                }
            }
        }
    }

    return b.to_xml
end

Instance Method Details

#supported_modelObject



31
32
33
34
35
36
37
# File 'lib/cwmp/message.rb', line 31

def supported_model
    if @raw_xml_message =~ /InternetGatewayDevice/
        return 'TR-098'
    else
        return 'TR-181'
    end
end

#to_sObject



23
24
25
# File 'lib/cwmp/message.rb', line 23

def to_s
    return "CWMP Mess #{@message_type}"
end

#xmlObject



27
28
29
# File 'lib/cwmp/message.rb', line 27

def xml
    return @raw_xml_message
end