network-utility 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +2 -0
  3. data/document/acl-M6000-16E.md +27 -0
  4. data/document/acl-M6000-18S.md +27 -0
  5. data/document/acl-M6000-8.md +27 -0
  6. data/document/acl-M6000-8E.md +27 -0
  7. data/document/acl-MA5200G-8.md +204 -0
  8. data/document/acl-ME60-16.md +177 -0
  9. data/document/acl-ME60-X16.md +177 -0
  10. data/document/acl-NE40E-X16.md +204 -0
  11. data/document/acl-NE40E-X16A.md +204 -0
  12. data/document/acl-NE40E-X8.md +204 -0
  13. data/document/acl-NE40E.md +204 -0
  14. data/document/acl-NE5000E-20.md +25 -0
  15. data/document/acl-NE5000E-X16.md +25 -0
  16. data/document/acl-NE5000E-X16A.md +25 -0
  17. data/document/acl-NE80E.md +204 -0
  18. data/document/bgp-CR16010H-F.md +25 -0
  19. data/document/bgp-CR16018-F.md +25 -0
  20. data/document/bgp-CR19000-20.md +25 -0
  21. data/document/bgp-M6000-16E.md +25 -0
  22. data/document/bgp-M6000-18S.md +25 -0
  23. data/document/bgp-M6000-8.md +25 -0
  24. data/document/bgp-M6000-8E.md +25 -0
  25. data/document/bgp-MA5200G-8.md +25 -0
  26. data/document/bgp-ME60-16.md +25 -0
  27. data/document/bgp-ME60-X16.md +25 -0
  28. data/document/bgp-NE40E-X16.md +25 -0
  29. data/document/bgp-NE40E-X16A.md +25 -0
  30. data/document/bgp-NE40E-X8.md +25 -0
  31. data/document/bgp-NE40E.md +25 -0
  32. data/document/bgp-NE5000E-20.md +25 -0
  33. data/document/bgp-NE5000E-X16.md +25 -0
  34. data/document/bgp-NE5000E-X16A.md +25 -0
  35. data/document/bgp-NE80E.md +25 -0
  36. data/document/config.md +1153 -0
  37. data/document/document.rb +27 -0
  38. data/document/if-ALCATEL7750.md +48 -0
  39. data/document/if-C7609.md +47 -0
  40. data/document/if-CR16010H-F.md +300 -0
  41. data/document/if-CR16018-F.md +300 -0
  42. data/document/if-CR19000-20.md +300 -0
  43. data/document/if-CRS-16.md +47 -0
  44. data/document/if-CX600-X16A.md +349 -0
  45. data/document/if-CX600-X8A.md +349 -0
  46. data/document/if-M6000-16E.md +652 -0
  47. data/document/if-M6000-18S.md +846 -0
  48. data/document/if-M6000-8.md +653 -0
  49. data/document/if-M6000-8E.md +653 -0
  50. data/document/if-MA5200G-8.md +357 -0
  51. data/document/if-ME60-16.md +357 -0
  52. data/document/if-ME60-X16.md +357 -0
  53. data/document/if-NE40E-X16.md +357 -0
  54. data/document/if-NE40E-X16A.md +357 -0
  55. data/document/if-NE40E-X8.md +357 -0
  56. data/document/if-NE40E.md +357 -0
  57. data/document/if-NE5000E-20.md +357 -0
  58. data/document/if-NE5000E-X16.md +357 -0
  59. data/document/if-NE5000E-X16A.md +357 -0
  60. data/document/if-NE8000E-X8.md +357 -0
  61. data/document/if-NE80E.md +357 -0
  62. data/document/if-NE8100-X8.md +357 -0
  63. data/document/if-Nokia7750.md +48 -0
  64. data/document/if-T8000-18.md +653 -0
  65. data/document/if-V6000.md +663 -0
  66. data/document/if-VNE9000.md +357 -0
  67. data/document/if-ZXCTN9000-18EA.md +762 -0
  68. data/document/if-ZXCTN9000-8EA.md +762 -0
  69. data/document/lic-M6000-16E.md +28 -0
  70. data/document/lic-M6000-18S.md +28 -0
  71. data/document/lic-M6000-8.md +28 -0
  72. data/document/lic-M6000-8E.md +28 -0
  73. data/document/lic-MA5200G-8.md +27 -0
  74. data/document/lic-ME60-16.md +27 -0
  75. data/document/lic-ME60-X16.md +27 -0
  76. data/document/lic-NE40E-X16.md +27 -0
  77. data/document/lic-NE40E-X16A.md +27 -0
  78. data/document/lic-NE40E-X8.md +27 -0
  79. data/document/log-M6000-16E.md +36 -0
  80. data/document/log-M6000-18S.md +36 -0
  81. data/document/log-M6000-8.md +36 -0
  82. data/document/log-M6000-8E.md +36 -0
  83. data/document/log-MA5200G-8.md +61 -0
  84. data/document/log-ME60-16.md +61 -0
  85. data/document/log-ME60-X16.md +61 -0
  86. data/document/log-NE40E-X16.md +61 -0
  87. data/document/log-NE40E-X16A.md +61 -0
  88. data/document/log-NE40E-X8.md +61 -0
  89. data/document/log-NE40E.md +61 -0
  90. data/document/log-NE5000E-20.md +61 -0
  91. data/document/log-NE5000E-X16.md +61 -0
  92. data/document/log-NE5000E-X16A.md +61 -0
  93. data/document/log-NE80E.md +61 -0
  94. data/document/nat-CR16010H-F.md +27 -0
  95. data/document/nat-CR16018-F.md +27 -0
  96. data/document/nat-M6000-16E.md +27 -0
  97. data/document/nat-M6000-18S.md +27 -0
  98. data/document/nat-M6000-8.md +27 -0
  99. data/document/nat-M6000-8E.md +27 -0
  100. data/document/nat-ME60-16.md +44 -0
  101. data/document/nat-ME60-X16.md +44 -0
  102. data/document/nat-NE40E-X16.md +44 -0
  103. data/document/nat-NE40E-X16A.md +44 -0
  104. data/document/policy-M6000-16E.md +13 -0
  105. data/document/policy-M6000-18S.md +13 -0
  106. data/document/policy-M6000-8.md +13 -0
  107. data/document/policy-M6000-8E.md +13 -0
  108. data/document/policy-MA5200G-8.md +87 -0
  109. data/document/policy-ME60-16.md +87 -0
  110. data/document/policy-ME60-X16.md +87 -0
  111. data/document/policy-NE40E-X16.md +87 -0
  112. data/document/policy-NE40E-X16A.md +87 -0
  113. data/document/policy-NE40E-X8.md +87 -0
  114. data/document/policy-NE40E.md +87 -0
  115. data/document/policy-NE5000E-20.md +87 -0
  116. data/document/policy-NE5000E-X16.md +87 -0
  117. data/document/policy-NE5000E-X16A.md +87 -0
  118. data/document/policy-NE80E.md +87 -0
  119. data/document/pool-M6000-16E.md +126 -0
  120. data/document/pool-M6000-18S.md +126 -0
  121. data/document/pool-M6000-8.md +126 -0
  122. data/document/pool-M6000-8E.md +126 -0
  123. data/document/pool-MA5200G-8.md +138 -0
  124. data/document/pool-ME60-16.md +138 -0
  125. data/document/pool-ME60-X16.md +138 -0
  126. data/document/pool-NE40E-X16.md +138 -0
  127. data/document/pool-NE40E-X16A.md +138 -0
  128. data/document/pool-NE40E-X8.md +138 -0
  129. data/document/pool-NE40E.md +138 -0
  130. data/document/pool-NE80E.md +138 -0
  131. data/document/static-CR16010H-F.md +60 -0
  132. data/document/static-CR16018-F.md +60 -0
  133. data/document/static-CR19000-20.md +60 -0
  134. data/document/static-CX600-X16A.md +26 -0
  135. data/document/static-CX600-X8A.md +26 -0
  136. data/document/static-M6000-16E.md +104 -0
  137. data/document/static-M6000-18S.md +104 -0
  138. data/document/static-M6000-8.md +104 -0
  139. data/document/static-M6000-8E.md +104 -0
  140. data/document/static-MA5200G-8.md +82 -0
  141. data/document/static-ME60-16.md +82 -0
  142. data/document/static-ME60-X16.md +82 -0
  143. data/document/static-NE40E-X16.md +82 -0
  144. data/document/static-NE40E-X16A.md +81 -0
  145. data/document/static-NE40E-X8.md +82 -0
  146. data/document/static-NE40E.md +67 -0
  147. data/document/static-NE5000E-20.md +67 -0
  148. data/document/static-NE5000E-X16.md +67 -0
  149. data/document/static-NE5000E-X16A.md +67 -0
  150. data/document/static-NE8000E-X8.md +26 -0
  151. data/document/static-NE80E.md +67 -0
  152. data/document/static-NE8100-X8.md +26 -0
  153. data/document/static-T8000-18.md +34 -0
  154. data/document/static-ZXCTN9000-18EA.md +34 -0
  155. data/document/static-ZXCTN9000-8EA.md +34 -0
  156. data/document/system-M6000-16E.md +75 -0
  157. data/document/system-M6000-18S.md +76 -0
  158. data/document/system-M6000-8.md +75 -0
  159. data/document/system-M6000-8E.md +75 -0
  160. data/document/system-MA5200G-8.md +51 -0
  161. data/document/system-ME60-16.md +51 -0
  162. data/document/system-ME60-X16.md +51 -0
  163. data/document/system-NE40E-X16.md +51 -0
  164. data/document/system-NE40E-X16A.md +51 -0
  165. data/document/system-NE40E-X8.md +51 -0
  166. data/document/system-NE40E.md +51 -0
  167. data/document/system-NE5000E-20.md +51 -0
  168. data/document/system-NE5000E-X16.md +51 -0
  169. data/document/system-NE5000E-X16A.md +51 -0
  170. data/document/system-NE80E.md +51 -0
  171. data/document/telnet.md +332 -0
  172. data/network.rb +24 -0
  173. data/utility/ipv4_address.rb +266 -0
  174. data/utility/ipv6_address.rb +201 -0
  175. data/utility/mac_address.rb +77 -0
  176. data/utility/netmerge.rb +46 -0
  177. data/utility/route.rb +79 -0
  178. data/utility/whitelist.rb +21 -0
  179. metadata +258 -0
@@ -0,0 +1,652 @@
1
+
2
+ # M6000-16E 接口
3
+
4
+ ```ruby
5
+ @sign << ["M6000-16E", "接口配置"]
6
+ @sign << ["M6000-16E", "接口物理信息"]
7
+ @sign << ["M6000-16E", "接口基本信息"]
8
+ @sign << ["M6000-16E", "接口vlan信息"]
9
+ @sign << ["M6000-16E", "接口acl信息"]
10
+ @sign << ["M6000-16E", "接口urpf信息"]
11
+ @sign << ["M6000-16E", "接口mpls信息"]
12
+ @sign << ["M6000-16E", "接口lacp信息"]
13
+ @sign << ["M6000-16E", "接口am信息"]
14
+ @sign << ["M6000-16E", "接口uim信息"]
15
+ @sign << ["M6000-16E", "接口isis信息"]
16
+ @sign << ["M6000-16E", "接口multicast信息"]
17
+ @sign << ["M6000-16E", "接口QoS"]
18
+ @sign << ["M6000-16E", "接口流策略"]
19
+ @sign << ["M6000-16E", "接口统计"]
20
+ @sign << ["M6000-16E", "接口URPF"]
21
+ @sign << ["M6000-16E", "接口接入类型"]
22
+ @sign << ["M6000-16E", "特殊接口配置"]
23
+ @sign << ["M6000-16E", "物理接口配置"]
24
+ @sign << ["M6000-16E", "子接口配置"]
25
+ @sign << ["M6000-16E", "接口分捡"]
26
+ @sign << ["M6000-16E", "端口识别"]
27
+ @sign << ["M6000-16E", "端口MAC"]
28
+ @sign << ["M6000-16E", "端口管理状态"]
29
+ @sign << ["M6000-16E", "接口描述"]
30
+ @sign << ["M6000-16E", "接口地址"]
31
+ @sign << ["M6000-16E", "接口开关"]
32
+ @sign << ["M6000-16E", "接口vpn实例"]
33
+ @sign << ["M6000-16E", "聚合接口判定"]
34
+ @sign << ["M6000-16E", "聚合接口分捡"]
35
+ @sign << ["M6000-16E", "聚合逻辑接口"]
36
+ @sign << ["M6000-16E", "聚合接口查询"]
37
+ @sign << ["M6000-16E", "vlan分捡"]
38
+ @sign << ["M6000-16E", "vlan统计"]
39
+ @sign << ["M6000-16E", "端口去0"]
40
+ @sign << ["M6000-16E", "统计接口"]
41
+
42
+ module M6000_16E
43
+
44
+ #####################################################################################################
45
+ # 接口/端口配置的基本查询
46
+ # 接口集合 => 接口分检 => 物理接口集合,子接口集合,特殊接口集合
47
+ # M6000的接口信息获取麻烦得多,需要针对各类配置模块获取接口相关的信息,所以全局配置都要解析一次,目前要解析的清单如下:
48
+ # 1. 接口物理信息
49
+ # 2. 接口基本信息
50
+ # 3. 接口vlan信息
51
+ # 4. 接口acl信息
52
+ # 5. 接口urpf信息
53
+ # 6. 接口mpls信息
54
+ # 7. 接口lacp信息
55
+ # 8. 接口am信息
56
+ # 9. 接口uim信息
57
+ # 10.接口isis信息
58
+ # 11.接口multicast信息
59
+ #####################################################################################################
60
+ def 接口配置 正文
61
+ 接口表 = {}
62
+ # these will be instancized!
63
+ [self.接口物理信息(正文), self.接口基本信息(正文), self.接口vlan信息(正文), self.接口acl信息(正文),
64
+ self.接口urpf信息(正文), self.接口mpls信息(正文), self.接口am信息(正文), self.接口uim信息(正文),
65
+ self.接口isis信息(正文), self.接口multicast信息(正文), self.接口lacp信息(正文)
66
+ ].each do|infolist|
67
+ infolist.each do|intf,text|
68
+ 接口表[intf]||=[]
69
+ 接口表[intf] << text
70
+ end
71
+ end
72
+ 接口表
73
+ end
74
+
75
+ def 接口物理信息 正文
76
+ tag = 正文["PORT-PHYSICAL-INFO"] ? "PORT-PHYSICAL-INFO" : "port-physical-config"
77
+ 接口物理表 = {}
78
+ if tag == "PORT-PHYSICAL-INFO"
79
+ (正文[tag]||"").split("\n!")\
80
+ .collect{|l|"<#{tag}>\n"+l.strip+"\n!\n</#{tag}>" if l!=' '}\
81
+ .compact.each{|接口|接口物理表[/interface (.)*/.match(接口)[0].to_s.strip] = 接口}
82
+ elsif tag == "port-physical-config"
83
+ (正文[tag]||"").split("\n$")\
84
+ .collect{|l|"<#{tag}>\n"+l.strip+"\n!\n</#{tag}>" if l!="\n!"}\
85
+ .compact.each{|接口|接口物理表[/interface (.)*/.match(接口)[0].to_s.strip] = 接口}
86
+ end
87
+ 接口物理表
88
+ end
89
+
90
+ def 接口基本信息 正文
91
+ tag = 正文["INTERFACE"] ? "INTERFACE" : "if-intf"
92
+ 接口基本表 = {}
93
+ if tag== "INTERFACE"
94
+ (正文[tag]||"").split("\n!")\
95
+ .collect{|l|"<#{tag}>\n"+l.strip+"\n!\n</#{tag}>" \
96
+ if l!=' ' && l.include?('interface')}\
97
+ .compact.each{|接口|接口基本表[/interface (.)*/.match(接口)[0].to_s.strip] = 接口}
98
+ elsif tag=="if-intf"
99
+ (正文[tag]||"").split("\n$")\
100
+ .collect{|l|"<#{tag}>\n"+l.strip+"\n!\n</#{tag}>" \
101
+ if l!=' ' && l.include?('interface')}\
102
+ .compact.each{|接口|接口基本表[/interface (.)*/.match(接口)[0].to_s.strip] = 接口}
103
+ end
104
+ 接口基本表
105
+ end
106
+
107
+ def 接口vlan信息 正文
108
+ tag = 正文["VLAN"] ? "VLAN" : "vlan"
109
+ 接口vlan表 = {}
110
+ if tag == "VLAN"
111
+ context,fragments = TextAbstract.draw_fragments (正文[tag]||""), /^ interface (.)*/, /^ \$/
112
+ head,tail = "<#{tag}>\n#{context.split("\n")[0]}\n","!\n</#{tag}>"
113
+ fragments.each{|frag| 接口vlan表[/interface (.)*/.match(frag)[0].to_s.strip] = head+frag+tail}
114
+ elsif tag == "vlan"
115
+ context,fragments = TextAbstract.draw_fragments (正文[tag]||""), /^ interface (.)*/, /^ \$/
116
+ head,tail = "<#{tag}>\n#{context.split("\n")[0]}\n","!\n</#{tag}>"
117
+ fragments.each{|frag| 接口vlan表[/interface (.)*/.match(frag)[0].to_s.strip] = head+frag+tail}
118
+ end
119
+ 接口vlan表
120
+ end
121
+
122
+ def 接口acl信息 正文
123
+ tag = 正文["PORT_ACL"] ? "PORT_ACL" : "port-acl"
124
+ 接口acl表 = {}
125
+ if tag =="PORT_ACL"
126
+ (正文[tag]||"").split("\n!")\
127
+ .collect{|l|"<#{tag}>\n"+l.strip+"\n!\n</#{tag}>" if l!="\n!"}\
128
+ .compact.each{|接口|接口acl表[/interface (.)*/.match(接口)[0].to_s.strip]=接口}
129
+ elsif tag == "port-acl"
130
+ (正文[tag]||"").split("\n$")\
131
+ .collect{|l|"<#{tag}>\n"+l.strip+"\n!\n</#{tag}>" if l!="\n!"}\
132
+ .compact.each{|接口|接口acl表[/interface (.)*/.match(接口)[0].to_s.strip]=接口}
133
+ end
134
+ 接口acl表
135
+ end
136
+
137
+ def 接口urpf信息 正文
138
+ tag = 正文["URPF"] ? "URPF" : "urpf"
139
+ 接口urpf表 = {}
140
+ if tag == "URPF"
141
+ (正文[tag]||"").split("\n!")\
142
+ .collect{|l|"<#{tag}>\n"+l.strip+"\n!\n</#{tag}>" if l!="\n!"}\
143
+ .compact.each{|接口|接口urpf表[/interface (.)*/.match(接口)[0].to_s.strip]=接口}
144
+ elsif tag == "urpf"
145
+ (正文[tag]||"").split("\n$")\
146
+ .collect{|l|"<#{tag}>\n"+l.strip+"\n!\n</#{tag}>" if l!="\n!"}\
147
+ .compact.each{|接口|接口urpf表[/interface (.)*/.match(接口)[0].to_s.strip]=接口}
148
+ end
149
+ 接口urpf表
150
+ end
151
+
152
+ def 接口mpls信息 正文
153
+ tag = 正文["MPLS"] ? "MPLS" : "ldp"
154
+ 接口mpls表 = {}
155
+ if tag=="MPLS"
156
+ context,fragments = TextAbstract.draw_fragments (正文[tag]||""), /^ interface (.)*/, /^ \$/
157
+ head,tail = "<#{tag}>\n#{context[0..-3]}\n","!\n</#{tag}>" # context tail(!\n)
158
+ fragments.each{|frag|接口mpls表[/interface (.)*/.match(frag)[0].to_s.strip] = head+frag+tail}
159
+ elsif tag=="ldp"
160
+ context,fragments = TextAbstract.draw_fragments (正文[tag]||""), /^ interface (.)*/, /^ \$/
161
+ head,tail = "<#{tag}>\n#{context[0..-3]}\n","!\n</#{tag}>" # context tail(!\n)
162
+ fragments.each{|frag|接口mpls表[/interface (.)*/.match(frag)[0].to_s.strip] = head+frag+tail}
163
+ end
164
+ 接口mpls表
165
+ end
166
+
167
+ def 接口lacp信息 正文 # trunk
168
+ tag = 正文["LACP"] ? "LACP" : "lacp"
169
+ 接口lacp表 = {}
170
+ if tag=="LACP"
171
+ context,fragments = TextAbstract.draw_fragments (正文[tag]||""), /^ interface (.)*/, /^ \$/
172
+ head,tail = "<#{tag}>\n#{context[0..-3]}\n","!\n</#{tag}>" # context tail(!\n)
173
+ fragments.each{|frag|接口lacp表[/interface (.)*/.match(frag)[0].to_s.strip] = head+frag+tail}
174
+ elsif tag=="lacp"
175
+ context,fragments = TextAbstract.draw_fragments (正文[tag]||""), /^ interface (.)*/, /^ \$/
176
+ head,tail = "<#{tag}>\n#{context[0..-3]}\n","!\n</#{tag}>" # context tail(!\n)
177
+ fragments.each{|frag|接口lacp表[/interface (.)*/.match(frag)[0].to_s.strip] = head+frag+tail}
178
+ end
179
+ 接口lacp表
180
+ end
181
+
182
+ def 接口am信息 正文
183
+ tag = 正文["AM"] ? "AM" : "am"
184
+ 接口am表 = {}
185
+ if tag == "AM"
186
+ context,fragments = TextAbstract.draw_fragments (正文[tag]||""), /^ interface (.)*/, /^ \$/
187
+ head,tail = "<#{tag}>\n#{context[0..-3]}\n","!\n</#{tag}>" # context tail(!\n)
188
+ fragments.each{|frag|接口am表[/interface (.)*/.match(frag)[0].to_s.strip] = head+frag+tail}
189
+ elsif tag == "am"
190
+ context,fragments = TextAbstract.draw_fragments (正文[tag]||""), /^ interface (.)*/, /^ \$/
191
+ head,tail = "<#{tag}>\n#{context[0..-3]}\n","!\n</#{tag}>" # context tail(!\n)
192
+ fragments.each{|frag|接口am表[/interface (.)*/.match(frag)[0].to_s.strip] = head+frag+tail}
193
+ end
194
+ 接口am表
195
+ end
196
+
197
+ def 接口uim信息 正文
198
+ tag = 正文["UIM"] ? "UIM" : "uim"
199
+ 接口uim表 = {}
200
+ if tag =="UIM"
201
+ za,vcc = TextAbstract.draw_fragments (正文[tag]||""), /^vcc\-configuration/, /^\!/
202
+ za,vbui= TextAbstract.draw_fragments (正文[tag]||""), /^vbui\-configuration/, /^\!/
203
+ # vcc
204
+ context,fragments = TextAbstract.draw_fragments vcc.join, /^ interface (.)*/, /^ \$/
205
+ head,tail = "<#{tag}>\n#{context[0..-3]}","!\n</#{tag}>" # context tail(\n!\n)
206
+ fragments.each{|frag|接口uim表[/interface (.)*/.match(frag)[0].to_s.strip] = head+frag+tail}
207
+ # vbui
208
+ context,fragments = TextAbstract.draw_fragments vbui.join, /^ interface (.)*/, /^ \$/
209
+ head,tail = "<#{tag}>\n#{context[0..-3]}","!\n</#{tag}>" # context tail(\n!\n)
210
+ fragments.each{|frag|接口uim表[/interface (.)*/.match(frag)[0].to_s.strip] = head+frag+tail}
211
+ elsif tag =="uim"
212
+ za,vcc = TextAbstract.draw_fragments (正文[tag]||""), /^vcc\-configuration/, /^\$/
213
+ za,vbui= TextAbstract.draw_fragments (正文[tag]||""), /^vbui\-configuration/, /^\$/
214
+ # vcc
215
+ context,fragments = TextAbstract.draw_fragments vcc.join, /^ interface (.)*/, /^ \$/
216
+ head,tail = "<#{tag}>\n#{context[0..-3]}","!\n</#{tag}>" # context tail(\n!\n)
217
+ fragments.each{|frag|接口uim表[/interface (.)*/.match(frag)[0].to_s.strip] = head+frag+tail}
218
+ # vbui
219
+ context,fragments = TextAbstract.draw_fragments vbui.join, /^ interface (.)*/, /^ \$/
220
+ head,tail = "<#{tag}>\n#{context[0..-3]}","!\n</#{tag}>" # context tail(\n!\n)
221
+ fragments.each{|frag|接口uim表[/interface (.)*/.match(frag)[0].to_s.strip] = head+frag+tail}
222
+ end
223
+ 接口uim表
224
+ end
225
+
226
+ def 接口isis信息 正文
227
+ tag = 正文["ISIS"] ? "ISIS" : "isis"
228
+ 接口isis表 = {}
229
+ if tag == "ISIS"
230
+ context,fragments = TextAbstract.draw_fragments (正文[tag]||""), /^ interface (.)*/, /^ \$/
231
+ head,tail = "<#{tag}>\n#{context[0..-3]}\n","!\n</#{tag}>" # context tail(\n!)
232
+ fragments.each{|frag|接口isis表[/interface (.)*/.match(frag)[0].to_s.strip] = head+frag+tail}
233
+ elsif tag == "isis"
234
+ context,fragments = TextAbstract.draw_fragments (正文[tag]||""), /^ interface (.)*/, /^ \$/
235
+ head,tail = "<#{tag}>\n#{context[0..-3]}\n","!\n</#{tag}>" # context tail(\n!)
236
+ fragments.each{|frag|接口isis表[/interface (.)*/.match(frag)[0].to_s.strip] = head+frag+tail}
237
+ end
238
+ 接口isis表
239
+ end
240
+
241
+ def 接口multicast信息 正文
242
+ tag = 正文["MULTICAST"] ? "MULTICAST" : "multicast"
243
+ 接口multicast表 = {}
244
+ if tag == "MULTICAST"
245
+ za,pimsm = TextAbstract.draw_fragments (正文[tag]||""), /^ router pimsm/, /^ \$/
246
+ za,pimsm = TextAbstract.draw_fragments (正文[tag]||""), /^ router pim/, /^ \$/ unless pimsm[0]
247
+ za,igmp= TextAbstract.draw_fragments (正文[tag]||""), /^ router igmp/, /^ \$/
248
+ chead,ctail = "<#{tag}>\n#{za.split("\n")[0]}\n","!\n</#{tag}>" # common head
249
+ # pimsm
250
+ #begin
251
+ context,fragments = TextAbstract.draw_fragments pimsm[0],/^ interface (.)*/, /^ \$/
252
+ head,tail = context[0..-5],context[-4..-1] # open(... $\n)
253
+ fragments.each{|frag|接口multicast表[/interface (.)*/.match(frag)[0].to_s.strip] = chead+head+frag+tail+ctail}
254
+ #rescue;end
255
+ # igmp
256
+ context,fragments = TextAbstract.draw_fragments igmp.join, /^ interface (.)*/, /^ \$/
257
+ head,tail = context[0..-5],context[-4..-1] # open(... $\n)
258
+ fragments.each{|frag|接口multicast表[/interface (.)*/.match(frag)[0].to_s.strip] = chead+head+frag+tail+ctail}
259
+ elsif tag == "multicast"
260
+ za,pimsm = TextAbstract.draw_fragments (正文[tag]||""), /^ router pimsm/, /^ \$/
261
+ za,pimsm = TextAbstract.draw_fragments (正文[tag]||""), /^ router pim/, /^ \$/ unless pimsm[0]
262
+ za,igmp= TextAbstract.draw_fragments (正文[tag]||""), /^ router igmp/, /^ \$/
263
+ chead,ctail = "<#{tag}>\n#{za.split("\n")[0]}\n","!\n</#{tag}>" # common head
264
+ # pimsm
265
+ #begin
266
+ context,fragments = TextAbstract.draw_fragments pimsm[0].to_s, /^ interface (.)*/, /^ \$/
267
+ head,tail = context[0..-5],context[-4..-1] # open(... $\n)
268
+ fragments.each{|frag|接口multicast表[/interface (.)*/.match(frag)[0].to_s.strip] = chead+head+frag+tail+ctail}
269
+ #rescue;end
270
+ # igmp
271
+ context,fragments = TextAbstract.draw_fragments igmp.join, /^ interface (.)*/, /^ \$/
272
+ head,tail = context[0..-5],context[-4..-1] # open(... $\n)
273
+ fragments.each{|frag|接口multicast表[/interface (.)*/.match(frag)[0].to_s.strip] = chead+head+frag+tail+ctail}
274
+ end
275
+ 接口multicast表
276
+ end
277
+
278
+ # func: 端口应用QoS模板
279
+ def 接口QoS 正文
280
+ # QoS有一部分在流策略,这里只解析car限速
281
+ tag = 正文["CAR"] ? 'CAR' : 'car'
282
+ cars = {};current = nil; cars[current] = {}
283
+ lines = 正文[tag].to_s.split("\n")
284
+ lines.each_with_index do|line, index|
285
+ if line.include?('interface')
286
+ current = line.split('interface ').last
287
+ cars[current] ||= {}
288
+ end
289
+ if line.include?('rate-limit ')
290
+ if line.size==80 && lines[index+1][0..1]!=' '
291
+ words = (line+lines[index+1]).split(" ")
292
+ else
293
+ words = line.split(" ")
294
+ end
295
+ cars[current]['direction'] = words[words.index('rate-limit')+1]
296
+ cars[current]['cir'] = words.index('cir') ? words[(words.index('cir')+1)..(words.index('cir')+2)].join : ''
297
+ cars[current]['pir'] = words.index('pir') ? words[(words.index('pir')+1)..(words.index('pir')+2)].join : ''
298
+ cars[current]['cbs'] = words.index('cbs') ? words[words.index('cbs')+1]+'bytes' : ''
299
+ cars[current]['pbs'] = words.index('pbs') ? words[words.index('pbs')+1]+'bytes' : ''
300
+ cars[current]['action'] = [
301
+ words.index('conform-action') ? words[words.index('conform-action')+1] : '',
302
+ words.index('exceed-action') ? words[words.index('exceed-action')+1] : '',
303
+ words.index('violate-action') ? words[words.index('violate-action')+1] : ''
304
+ ]
305
+ end
306
+ end
307
+ cars.delete(nil)
308
+ cars
309
+ end
310
+
311
+ # func: 端口应用流量模板
312
+ def 接口流策略 正文
313
+ tag = 正文["hqos"] ? 'hqos' : 'hqos'
314
+ svc_policy = {}
315
+ lines = 正文[tag].to_s.split("\n")
316
+ lines.each_with_index do|line, index|
317
+ if line.include?('service-policy')
318
+ words = line.split(' ')
319
+ interface = words[words.index('service-policy')+1]
320
+ direction = words[words.index('service-policy')+2]
321
+ template = words[words.index('service-policy')+3]
322
+ svc_policy[interface] ||= {}
323
+ svc_policy[interface][direction] = template
324
+ end
325
+ end
326
+ svc_policy
327
+ end
328
+
329
+ # func: 端口统计功能
330
+ def 接口统计 正文
331
+ tag = 正文["interface-performance"] ? 'interface-performance' : 'interface-performance'
332
+ intf_perf = {}; current = nil; intf_perf[current] = {}
333
+ lines = 正文[tag].to_s.split("\n")
334
+ lines.each_with_index do|line, index|
335
+ if line.include?('interface-performance')
336
+ current = line.split('interface ').last
337
+ end
338
+ if line.include?('traffic-statistics enable')
339
+ intf_perf[current] = :statistic_enable
340
+ end
341
+ end
342
+ intf_perf.delete(nil)
343
+ intf_perf
344
+ end
345
+
346
+ # func: 端口URPF功能
347
+ def 接口URPF 正文
348
+ 接口urpf表 = self.接口urpf信息 正文
349
+ urpf = {}
350
+ 接口urpf表.each do|intf, conf|
351
+ words = conf.split(' ')
352
+ addr = words.join.include?('ipv4') ? 'ipv4' : 'ipv6'
353
+ mode = words[words.index('reachable-via')+1]=='any' ? 'loose' : 'strict'
354
+ acl = words.index('acl-name') ? words[words.index('acl-name')+1] : 'none'
355
+ ignr = words.include?('ignore-default-route') ? 'ignore-default-route' : 'none'
356
+ urpf[intf.split(' ').last] = {'addr'=>addr, 'mode'=>mode, 'acl'=>acl, 'ignore'=>ignr}
357
+ end
358
+ urpf
359
+ end
360
+
361
+ # func: 端口接入类型
362
+ def 接口接入类型 正文
363
+ 接口uim表 = self.接口uim信息 正文
364
+ access_type = {}
365
+ 接口uim表.each do|intf, conf|
366
+ type = conf.include?('ip-access-type') ? conf.split('ip-access-type ').last.split("\n").first : nil
367
+ access_type[intf.split(' ').last] = type if type
368
+ end
369
+ access_type
370
+ end
371
+
372
+ def 特殊接口配置 接口集合
373
+ 特殊接口集合 = []
374
+ 接口集合.each do|key,configs|
375
+ 特殊接口集合 << [key]+configs if key.include?('loopback') || key.include?('null') || \
376
+ key.include?('extimer') || key.include?('vbui') || key.include?('spi') || \
377
+ key.include?('gcvi') || key.include?('guvi') || key.include?('mgmt_eth') || \
378
+ key.include?('qx_eth') || key.include?('qx') || key.include?('gre_tunnel')
379
+ end
380
+ 特殊接口集合
381
+ end
382
+
383
+ def 物理接口配置 接口集合,特殊接口集合=nil
384
+ 物理接口集合 = []
385
+ 例外 = (特殊接口集合 ? 特殊接口集合 : (self.特殊接口配置 接口集合)).collect{|c|c[0]}
386
+ 接口集合.each do|key,configs|
387
+ 物理接口集合 << [key]+configs unless 例外.include?(key) || key.include?('.')
388
+ end
389
+ 物理接口集合
390
+ end
391
+
392
+ def 子接口配置 接口集合,特殊接口集合=nil
393
+ 子接口集合 = []
394
+ 例外 = (特殊接口集合 ? 特殊接口集合 : (self.特殊接口配置 接口集合)).collect{|c|c[0]}
395
+ 接口集合.each do|key,configs|
396
+ 子接口集合 << [key]+configs if !例外.include?(key) && key.include?('.')
397
+ end
398
+ 子接口集合
399
+ end
400
+
401
+ def 接口分捡 接口集合
402
+ 特殊接口集合 = self.特殊接口配置 接口集合
403
+ 物理接口集合 = self.物理接口配置 接口集合,特殊接口集合
404
+ 子接口集合 = self.子接口配置 接口集合,特殊接口集合
405
+ return 物理接口集合,子接口集合,特殊接口集合
406
+ end
407
+
408
+
409
+ #####################################################################################################
410
+ # 端口描述信息相关
411
+ #####################################################################################################
412
+
413
+ # func: 根据一个端口的描述信息,给出其格式化的类型、连接符、端口编号
414
+ def 端口识别 描述
415
+ 描述 = 描述[0] if 描述.instance_of?(Array) # M6000取接口配置中名称部分 [name,<tag>...</tag>,...]
416
+ 连接符 = '-'
417
+ type = /xgei|gei|smartgroup|loopback|extimer|eth_dslgroupvbui|vbui|vlan|virtual_template|null|guvi|gcvi|gps|gre_tunnel|mgmt_eth|qx_eth|qx|spi/.match(描述)
418
+ 类型 = type ? type.to_s : '未知类型'
419
+ port = /(\d+|\/|\.)*(\d+)/.match(描述.split(类型).join)
420
+ 端口 = port ? port.to_s : '未知端口'
421
+ 连接符 = '' if ['smartgroup','eth_dslgroup','loopback','vbui','vlan','virtual_template','gre_tunnel','null','qx'].include?(类型)
422
+ 端口 = '' if 类型=='mgmt_eth'
423
+ return 类型,连接符,端口
424
+ end
425
+
426
+ # func: 根据一个端口的描述信息,给出其mac地址,若无mac则返回nil
427
+ def 端口MAC 描述
428
+ 描述.each_line do|line|
429
+ if pattern = /\, address is (.+)/.match(line)
430
+ matcher = /[\d|A-F|a-f]+\.[\d|A-F|a-f]+\.[\d|A-F|a-f]+/.match(pattern[1].strip)
431
+ return pattern[1].strip if matcher.to_s==pattern[1].strip
432
+ end
433
+ end
434
+ return nil
435
+ end
436
+
437
+ # func: 根据一个端口的描述信息,给出其管理状态是打开/关闭的判断
438
+ def 端口管理状态 描述
439
+ 描述 = 描述[1..-1].join("\n") if 描述.instance_of?(Array) # M6000取接口配置中名称部分 [name,<tag>...</tag>,...]
440
+ 管理状态 = true
441
+ 描述.split("\n").each do|line|
442
+ 管理状态 = false if line.include?("shutdown") && !line.include?("no shutdown")
443
+ end
444
+ 管理状态
445
+ end
446
+
447
+ # func: 根据一个端口的配置给出其描述
448
+ def 接口描述 接口配置
449
+ 描述 = ''
450
+ 接口配置.join("\n").each_line do|line| if line.strip[0..10]=='description'
451
+ 描述 = line.split('description')[1..-1].join().strip; break
452
+ end end
453
+ 描述.to_s
454
+ end
455
+
456
+ # func: 根据一个端口的配置给出其配置的接口地址
457
+ def 接口地址 接口配置
458
+ 地址集 = []
459
+ 接口配置.join("\n").each_line do|line|
460
+ if line.strip[0..9]=='ip address'
461
+ 地址集 << line.gsub('secondary','').split('ip address')[-1].strip.split(' ')
462
+ end
463
+ if line.strip[0..11]=='ipv6 address'
464
+ 地址集 << line.gsub('secondary','').split('ipv6 address')[-1].strip.split('/')
465
+ end
466
+ end
467
+ 地址集
468
+ end
469
+
470
+ # func: 根据一个端口的配置给出其开关状态(配置层面的"端口管理状态")
471
+ def 接口开关 接口配置
472
+ 描述 = '' # for phy_if is shutdown, for sub_if,smartgroup are open
473
+ 接口配置.join("\n").each_line do|line|
474
+ if line.include?("no shutdown") and !line.include?('description')
475
+ 描述 = 'no shutdown'; break
476
+ end
477
+ if line.include?("smartgroup")
478
+ 描述 = 'no shutdown'; break
479
+ end
480
+ if line.include?("shutdown") and !line.include?('no') and !line.include?('description')
481
+ 描述 = 'shutdown'; break
482
+ end
483
+ end
484
+ 描述
485
+ end
486
+
487
+ # func: 根据一个端口的配置给出其关联的vpn实例
488
+ def 接口vpn实例 接口配置
489
+ 实例 = ''
490
+ 接口配置.join("\n").each_line do|line|
491
+ 实例 = "vpn-inst:" + /vrf forwarding .+/.match(line).to_s.split(" ")[-1] if /vrf forwarding .+/.match(line)
492
+ end
493
+ 实例
494
+ end
495
+
496
+ #####################################################################################################
497
+ # 聚合接口判定相关
498
+ #####################################################################################################
499
+
500
+ # func: 根据一个接口的描述信息,给出其所属聚合接口的信息,若非聚合端口返回空
501
+ def 聚合接口判定 配置
502
+ 配置.join.split("\n").each do|描述|
503
+ if 描述.include?("smartgroup") && 描述.include?("mode") &&
504
+ !描述.include?("description") && !self.端口识别(配置).join.include?("smartgroup")
505
+ return {self.端口识别(配置).join=>"smartgroup"+描述.strip.split(" ")[1]}
506
+ end
507
+ end;{}
508
+ end
509
+
510
+ # func: 给出聚合接口和物理接口的集合,通过计算找出所有聚合接口的集合
511
+ def 聚合接口分捡 聚合接口,物理接口集合
512
+ 聚合接口 = self.端口识别(聚合接口)
513
+ 聚合接口集合 = [聚合接口.join]
514
+ 物理接口集合.each do|物理接口| 物理接口.join.each_line do|line|
515
+ if line.include?("smartgroup") && !line.include?("description")
516
+ aggrnum = line.strip.split(" ")[1]
517
+ 聚合接口集合 << self.端口识别(物理接口).join if ['smartgroup','',aggrnum].join==聚合接口.join
518
+ end
519
+ end end
520
+ 聚合接口集合
521
+ end
522
+
523
+ # func: 根据一个接口的描述信息,给出其所属聚合接口的逻辑接口,若无返回空
524
+ def 聚合逻辑接口 配置
525
+ 配置.join.split("\n").each do|描述|
526
+ if 描述.include?("nas logic-interface")
527
+ num = 描述.split(" ")
528
+ return [num[-5],num[-3],num[-1]].join('/')
529
+ end
530
+ end
531
+ return nil
532
+ end
533
+
534
+ # func: 给出聚合接口查询命令的返回结果,提取接口对应的物理接口,若无返回空
535
+ def 聚合接口查询 查询报文
536
+ return [] if 查询报文.include?("Invalid input") or 查询报文.include?("No such interface")
537
+ parts = 查询报文.split("--------------------------------------------------------------------------------")
538
+ return parts[1].to_s.split("\n").map{|s|s.split(" ")}.select{|s|s.size>7}.map{|s|s.first.split('[').first}
539
+ end
540
+
541
+ #####################################################################################################
542
+ # 接口VLAN相关
543
+ # 对接口vlan配置的解析
544
+ # dot1q : [vlan, ...]
545
+ # qinq : [[pvlan, (cvlan..cvlan)], [pvlan, cvlan], ...]
546
+ # vlan : [(cvlan..cvlan), cvlan, ...]
547
+ #####################################################################################################
548
+ def vlan分捡 接口配置
549
+ vlan = {}
550
+ vlan_part = 接口配置.find{|配置|(配置.include?("<VLAN>")&&配置.include?("</VLAN>")) || (配置.include?("<vlan>")&&配置.include?("</vlan>"))} || ""
551
+ vlan_part.each_line do|line| next if line.include?('no')
552
+ if pattern = /encapsulation-dot1q range (.+)/.match(line)
553
+ dot1q = eval(pattern[1].to_s.gsub('-','..')) # Range or Integer
554
+ vlan['dot1q'] ||= [];vlan['dot1q'] << dot1q;next
555
+ end
556
+ if pattern = /encapsulation-dot1q (\d+)/.match(line)
557
+ dot1q = eval(pattern[1].to_s)
558
+ vlan['dot1q'] ||= [];vlan['dot1q'] << dot1q;next
559
+ end
560
+ if pattern = /qinq range internal-vlan-range (.+) external-vlan-range (.+)/.match(line)
561
+ vlan['qinq'] ||= []
562
+ exvlan = eval(pattern[2].to_s.gsub('-','..')) # Range or Integer
563
+ invlan = eval(pattern[1].to_s.gsub('-','..'))
564
+ if exvlan.instance_of?(Range)
565
+ exvlan.each{|exv|vlan['qinq'] << [exv,invlan]}
566
+ elsif exvlan.instance_of?(Integer) # Fixnum
567
+ vlan['qinq'] << [exvlan,invlan]
568
+ end;next
569
+ end
570
+ if pattern = /qinq internal-vlanid (\d+) external-vlanid (\d+)/.match(line)
571
+ qinq = [pattern[2].to_i,pattern[1].to_i]
572
+ vlan['qinq'] ||= [];vlan['qinq'] << qinq;next
573
+ end
574
+ end
575
+ return vlan # {vlan:[ int|range ] qinq:[ [int,int|range] ] dot1q:[ int ]}
576
+ end
577
+
578
+ def vlan统计 name,物理接口集合,子接口集合
579
+ bas子接口数据库,聚合接口表 = {},[]
580
+ 聚合接口集合 = 物理接口集合.select{|物理接口|self.端口识别(物理接口)[0]=='smartgroup'}
581
+ 聚合接口表 += 聚合接口集合.collect{|聚合接口|self.聚合接口分捡(聚合接口,物理接口集合)}
582
+
583
+ 子接口集合.each do|接口配置|
584
+ 物理接口名称 = self.端口识别(接口配置).join.split(".")[0]
585
+ 物理接口 = 物理接口集合.find{|物理接口|物理接口[0].split(" ")[1]==(物理接口名称)}
586
+ next unless self.端口管理状态(物理接口) # 物理接口关闭的不统计
587
+ next unless self.端口管理状态(接口配置) # 子接口关闭的不统计
588
+
589
+ vlan配置 = {}
590
+ self.vlan分捡(接口配置).each do|type,data|
591
+ if type=='vlan' || type=='dot1q'
592
+ vlan配置[4096] ||= []; vlan配置[4096] += data # 用4096表示单层vlan
593
+ elsif type=='qinq'
594
+ data.each{|pvlan,cvlan|vlan配置[pvlan] ||= []; vlan配置[pvlan] << cvlan}
595
+ end
596
+ end
597
+
598
+ 子接口名称 = self.端口识别(接口配置)
599
+ if 子接口名称[0].include?("gei")
600
+ # 子接口索引 = ["eth--"+子接口名称[-1].split(".")[0].split('/')[-3..-1].join(',')] # AIBOS风格
601
+ 子接口索引 = [子接口名称.join.split(".")[0]] # 原生风格
602
+ end
603
+ if 子接口名称[0].include?("smartgroup") &&
604
+ 聚合接口组 = 聚合接口表.find{|聚合接口组|聚合接口组.include?(子接口名称.join.split('.')[0])}
605
+ 聚合接口的等效名称 = 聚合接口组.clone;
606
+ # 聚合接口的等效名称.delete(子接口名称.join.split('.')[0]) # 除了smartgroup自身,为所有等效接口创建 # 是否保留smartgroup是个争议
607
+ 子接口索引 = 聚合接口的等效名称.map do|等效名称|
608
+ # "eth--"+self.端口识别(等效名称)[-1].split(".")[0].split('/')[-3..-1].join(',') # AIBOS风格
609
+ self.端口识别(等效名称).join.split(".")[0] # 原生风格
610
+ end
611
+ # 子接口索引 << "trunk--"+[255,0,子接口名称[2].split('.')[0]].join(',') # AIBOS风格
612
+ 子接口索引 << 子接口名称.join.split(".")[0] # 原生风格
613
+ end
614
+
615
+ bas子接口数据库[name] ||= {}
616
+ 子接口索引.each do|索引|
617
+ bas子接口数据库[name][索引] ||= {}
618
+ vlan配置.each do|pv,cv|
619
+ bas子接口数据库[name][索引][pv] ||= []
620
+ bas子接口数据库[name][索引][pv] += cv
621
+ bas子接口数据库[name][索引][pv].uniq!
622
+ end
623
+ end
624
+ end
625
+ return bas子接口数据库
626
+ end
627
+
628
+
629
+ #####################################################################################################
630
+ # 接口相关统计信息的处理
631
+ #####################################################################################################
632
+
633
+ # gei-x/x/x.00000xxx => gei-x/x/x.xxx
634
+ # 一些统计场合子接口会补前置0,这里可以将其去掉
635
+ def 端口去0 描述
636
+ if 描述.include?("00") && 描述.include?('.')
637
+ 接口,子接口 = 描述.split(".")
638
+ [接口,子接口.to_i.to_s].join(".")
639
+ else
640
+ 描述
641
+ end
642
+ end
643
+
644
+ # 针对show intf-statistics utilization phy-interface-only
645
+ def 统计接口 文本
646
+ 文本.split("\n").inject([]) do|表格, 行|
647
+ 表格 << 行.split(" ") if 行.include?("gei-") or 行.include?("smartgroup") or 行.include?("spi-")
648
+ 表格 # [interface, in-bps, in-uti, out-bps, out-uti, in-errors, in-dbm, out-dbm]
649
+ end
650
+ end
651
+ end
652
+ ```