Source for file docsis_classifier.php

Documentation is available at docsis_classifier.php

  1. <?php
  2. /**
  3. * DOCSIS Packet Classifiers
  4. *
  5. * @author David Eder <david@eder.us>
  6. * @copyright 2004 David Eder
  7. * @package docsis_config
  8. * @version .3
  9. */
  10.  
  11. /**
  12. */
  13. require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'docsis_common.php');
  14. require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'docsis_error.php');
  15. require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'docsis_vendor.php');
  16.  
  17. define('DOCSIS_UPSTREAM_PACKET_CLASSIFIER', 22);
  18. define('DOCSIS_DOWNSTREAM_PACKET_CLASSIFIER', 23);
  19.  
  20. define('DOCSIS_PACKET_CLASSIFIER_REFERENCE', 1);
  21. define('DOCSIS_PACKET_CLASSIFIER_IDENTIFIER', 2);
  22. define('DOCSIS_PACKET_CLASSIFIER_FLOW_REFERENCE', 3);
  23. define('DOCSIS_PACKET_CLASSIFIER_FLOW_IDENTIFIER', 4);
  24. define('DOCSIS_PACKET_CLASSIFIER_RULE_PRIORITY', 5);
  25. define('DOCSIS_PACKET_CLASSIFIER_ACTIVATION_STATE', 6);
  26. define('DOCSIS_PACKET_CLASSIFIER_DSC_ACTION', 7);
  27. define('DOCSIS_PACKET_CLASSIFIER_ERROR', 8);
  28. define('DOCSIS_PACKET_CLASSIFIER_IP_PACKET', 9);
  29. define('DOCSIS_PACKET_CLASSIFIER_IP_PACKET_TOS', 1);
  30. define('DOCSIS_PACKET_CLASSIFIER_IP_PACKET_PROTOCOL', 2);
  31. define('DOCSIS_PACKET_CLASSIFIER_IP_PACKET_SOURCE_ADDRESS', 3);
  32. define('DOCSIS_PACKET_CLASSIFIER_IP_PACKET_SOURCE_MASK', 4);
  33. define('DOCSIS_PACKET_CLASSIFIER_IP_PACKET_DEST_ADDRESS', 5);
  34. define('DOCSIS_PACKET_CLASSIFIER_IP_PACKET_DEST_MASK', 6);
  35. define('DOCSIS_PACKET_CLASSIFIER_IP_PACKET_SOURCE_PORT_START', 7);
  36. define('DOCSIS_PACKET_CLASSIFIER_IP_PACKET_SOURCE_PORT_END', 8);
  37. define('DOCSIS_PACKET_CLASSIFIER_IP_PACKET_DEST_PORT_START', 9);
  38. define('DOCSIS_PACKET_CLASSIFIER_IP_PACKET_DEST_PORT_END', 10);
  39. define('DOCSIS_PACKET_CLASSIFIER_ETHERNET', 10);
  40. define('DOCSIS_PACKET_CLASSIFIER_ETHERNET_DEST_MAC', 1);
  41. define('DOCSIS_PACKET_CLASSIFIER_ETHERNET_SOURCE_MAC', 2);
  42. define('DOCSIS_PACKET_CLASSIFIER_ETHERNET_DSAP_TYPE', 3);
  43. define('DOCSIS_PACKET_CLASSIFIER_IEEE', 11);
  44. define('DOCSIS_PACKET_CLASSIFIER_IEEE_USER_PRIORITY', 1);
  45. define('DOCSIS_PACKET_CLASSIFIER_IEEE_VLAN_ID', 2);
  46.  
  47. /**
  48. * DOCSIS IP Packet Classifier
  49. *
  50. * @package docsis_config
  51. * @subpackage docsis_classifier
  52. */
  53. class docsis_ip_packet_classifier extends docsis_encoder_complex
  54. {
  55. /**
  56. * Constructor
  57. *
  58. * @param int $code docsis code
  59. * @param array $value predefined values
  60. */
  61. function docsis_ip_packet_classifier($code=DOCSIS_PACKET_CLASSIFIER_IP_PACKET, $value=array())
  62. {
  63. parent::docsis_encoder_complex($code, $value);
  64. }
  65.  
  66. /**
  67. * Set Type of Service - docsis 1.1
  68. *
  69. * The values of the field specify the matching parameters for the IP ToS byte rand and mask. An IP packet with IP ToS byte value "ip-tos"
  70. * matches this parameter if $low <= (ip-tos AND $mask) <= $high. If this field is ommitted, then comparison of IP packet ToS byte for
  71. * this entry is irrelavant.
  72. *
  73. * @param int $low
  74. * @param int $high
  75. * @param int $mask
  76. */
  77. function set_type_of_service($low, $high, $mask)
  78. {
  79. $this->value[DOCSIS_PACKET_CLASSIFIER_IP_PACKET_TOS] =
  80. new docsis_encoder_string(DOCSIS_PACKET_CLASSIFIER_IP_PACKET_TOS, chr($low) . chr($high) . chr($mask));
  81. }
  82.  
  83. /**
  84. * Set Protocol - docsis 1.1
  85. *
  86. * The value of the field specifies the matching value for the IP Protocol field (RFC-1700). If this parameter is ommitted, then
  87. * comparison of the IP header Protocol field is irrelevant.
  88. *
  89. * There are two special IP Protocol field values: "256" matches traffic with any IP Protocol value, and "257" matches both TCP and UDP
  90. * traffic. An entry that includes an IP Protocol field value greater than 257 must be invalidated for comparisons (i.e., no traffic can
  91. * match this entry).
  92. *
  93. * @param int $value
  94. */
  95. function set_protocol($value)
  96. {
  97. if($value < 0 || $value > 257) trigger_error('Protocol must be 0 to 257', E_USER_WARNING);
  98. $this->value[DOCSIS_PACKET_CLASSIFIER_IP_PACKET_PROTOCOL] = new docsis_encoder_ushort(DOCSIS_PACKET_CLASSIFIER_IP_PACKET_PROTOCOL, $value);
  99. }
  100.  
  101. /**
  102. * Set IP Source Address - docsis 1.1
  103. *
  104. * @param string $ip
  105. */
  106. function set_source_address($ip)
  107. {
  108. $this->value[DOCSIS_PACKET_CLASSIFIER_IP_PACKET_SOURCE_ADDRESS] = new docsis_encoder_ip(DOCSIS_PACKET_CLASSIFIER_IP_PACKET_SOURCE_ADDRESS, $ip);
  109. }
  110.  
  111. /**
  112. * Set IP Source Mask - docsis 1.1
  113. *
  114. * @param string $mask
  115. */
  116. function set_source_mask($mask)
  117. {
  118. $this->value[DOCSIS_PACKET_CLASSIFIER_IP_PACKET_SOURCE_MASK] = new docsis_encoder_ip(DOCSIS_PACKET_CLASSIFIER_IP_PACKET_SOURCE_MASK, $mask);
  119. }
  120.  
  121. /**
  122. * Set Destination Address - docsis 1.1
  123. *
  124. * @param string $ip
  125. */
  126. function set_dest_address($ip)
  127. {
  128. $this->value[DOCSIS_PACKET_CLASSIFIER_IP_PACKET_DEST_ADDRESS] = new docsis_encoder_ip(DOCSIS_PACKET_CLASSIFIER_IP_PACKET_DEST_ADDRESS, $ip);
  129. }
  130.  
  131. /**
  132. * Set Destination Mask - docsis 1.1
  133. *
  134. * @param string $mask
  135. */
  136. function set_dest_mask($mask)
  137. {
  138. $this->value[DOCSIS_PACKET_CLASSIFIER_IP_PACKET_DEST_MASK] = new docsis_encoder_ip(DOCSIS_PACKET_CLASSIFIER_IP_PACKET_DEST_MASK, $mask);
  139. }
  140.  
  141. /**
  142. * Set TCP/UDP Source Port Start - docsis 1.1
  143. *
  144. * @param int $start
  145. */
  146. function set_source_port_start($start)
  147. {
  148. $this->value[DOCSIS_PACKET_CLASSIFIER_IP_PACKET_SOURCE_PORT_START] =
  149. new docsis_encoder_ushort(DOCSIS_PACKET_CLASSIFIER_IP_PACKET_SOURCE_PORT_START, $start);
  150. }
  151.  
  152. /**
  153. * Set TCP/UDP Source Port End - docsis 1.1
  154. *
  155. * @param int $end
  156. */
  157. function set_source_port_end($end)
  158. {
  159. $this->value[DOCSIS_PACKET_CLASSIFIER_IP_PACKET_SOURCE_PORT_END] =
  160. new docsis_encoder_ushort(DOCSIS_PACKET_CLASSIFIER_IP_PACKET_SOURCE_PORT_END, $end);
  161. }
  162.  
  163. /**
  164. * Set TCP/UDP Destination Port Start - docsis 1.1
  165. *
  166. * @param int $start
  167. */
  168. function set_dest_port_start($start)
  169. {
  170. $this->value[DOCSIS_PACKET_CLASSIFIER_IP_PACKET_DEST_PORT_START] =
  171. new docsis_encoder_ushort(DOCSIS_PACKET_CLASSIFIER_IP_PACKET_DEST_PORT_START, $start);
  172. }
  173.  
  174. /**
  175. * Set TCP/UDP Destination Port End - docsis 1.1
  176. *
  177. * @param int $end
  178. */
  179. function set_dest_port_end($end)
  180. {
  181. $this->value[DOCSIS_PACKET_CLASSIFIER_IP_PACKET_DEST_PORT_END] = new docsis_encoder_ushort(DOCSIS_PACKET_CLASSIFIER_IP_PACKET_DEST_PORT_END, $end);
  182. }
  183. }
  184.  
  185. /**
  186. * DOCSIS Ethernet Packet Classifier
  187. *
  188. * @package docsis_config
  189. * @subpackage docsis_classifier
  190. */
  191. class docsis_ether_packet_classifier extends docsis_encoder_complex
  192. {
  193. /**
  194. * Constructor
  195. *
  196. * @param int $code docsis code
  197. * @param array $value predefined values
  198. */
  199. function docsis_ether_packet_classifier($code=DOCSIS_PACKET_CLASSIFIER_ETHERNET, $value=array())
  200. {
  201. parent::docsis_encoder_complex($code, $value);
  202. }
  203.  
  204. /**
  205. * Set Destination MAC Address - docsis 1.1
  206. *
  207. * @param string $mac
  208. */
  209. function set_dest_mac($mac)
  210. {
  211. $this->value[DOCSIS_PACKET_CLASSIFIER_ETHERNET_DEST_MAC] = new docsis_encoder_mac(DOCSIS_PACKET_CLASSIFIER_ETHERNET_DEST_MAC, $mac);
  212. }
  213.  
  214. /**
  215. * Set Source MAC Address - docsis 1.1
  216. *
  217. * @param string $mac
  218. */
  219. function set_source_mac($mac)
  220. {
  221. $this->value[DOCSIS_PACKET_CLASSIFIER_ETHERNET_SOURCE_MAC] = new docsis_encoder_mac(DOCSIS_PACKET_CLASSIFIER_ETHERNET_SOURCE_MAC, $mac);
  222. }
  223.  
  224. /**
  225. * Set Ethernet/DSAP/MacType - docsis 1.1
  226. *
  227. * $type, $eprot1, and $eprot2 indicate the format of the layer 3 protocol ID in the Ethernet packet as follows:
  228. *
  229. * If $type is 0, the rule does not use layer 3 protocol type as a matching criteria. $eprot1 and $eprot2 are ignored.
  230. *
  231. * If $type is 1, the rule applies only to frames with contain an Ethertype value. Ethertype values are contained in packets using the
  232. * DEC-Intel-Xeros (DIX) encapsulation or the RFC-1042 Sub-Network Access Protocol (SNAP) encapsulation formats. $eprot1 and $eprot2 give
  233. * the 16-bit value of the Ethertype that the packet must match in order to match the rule.
  234. *
  235. * If $type is 2, the rule applies only to frames using the IEEE 802.2 encapsulation format with a Destination Service (DSAP) other than
  236. * 0xAA (which is reserved for SNAP). The lower 8 bits of $eprot1,$eprot2 must match the DSAP byte of the packet in order to match the rule.
  237. *
  238. * If $type is 3, the rule applies only to MAC Management Messages (FC field 1100001x) with a "type" field of its MAC Management Message
  239. * header between the values of $eprot1 and $eprot2, inclusive. As exceptions, the following MAC Management message types must not be
  240. * classified, and are always transmitted on the primary service flow:
  241. * <ul>
  242. * <li>Type 4: RNG_REQ</li>
  243. * <li>Type 6: REG_REQ</li>
  244. * <li>Type 7: REG_RSP</li>
  245. * <li>Type 14: REG_ACK</li>
  246. * </ul>
  247. *
  248. * If $type is 4, the rule is considered a "catch-all" rule that matches all Data PDU packets. The rule does not match MAC Management
  249. * Messages. $eprot1 and $eprot2 are ignored.
  250. *
  251. * If the Ethernet frame contains an 802.1P/Q Tag Header (i.e., Ethertype 0x8100), this object applies to the embedded Ethertype field
  252. * within the 802.1P/Q header.
  253. *
  254. * @param int $type
  255. * @param int $eprot1
  256. * @param int $eprot2
  257. */
  258. function set_dsap_type($type, $eprot1=0, $eprot2=0)
  259. {
  260. $this->value[DOCSIS_PACKET_CLASSIFIER_ETHERNET_DSAP_TYPE] =
  261. new docsis_encoder_string(DOCSIS_PACKET_CLASSIFIER_ETHERNET_DSAP_TYPE, chr($type) . chr($eprot1) . chr($eprot2));
  262. }
  263. }
  264.  
  265. /**
  266. * DOCSIS IEEE 802 Packet Classifier
  267. *
  268. * @package docsis_config
  269. * @subpackage docsis_classifier
  270. */
  271. class docsis_ieee802_packet_classifier extends docsis_encoder_complex
  272. {
  273. /**
  274. * Constructor
  275. *
  276. * @param int $code docsis code
  277. * @param array $value predefined values
  278. */
  279. function docsis_ieee802_packet_classifier($code=DOCSIS_PACKET_CLASSIFIER_IEEE, $value=array())
  280. {
  281. parent::docsis_encoder_complex($code, $value);
  282. }
  283.  
  284. /**
  285. * Set IEEE 802.1P User Priority - docsis 1.1
  286. *
  287. * The values of the field specify the matching parameters for the IEEE 802.1P user_priority bits. An Ethernet packet with IEEE 802.1P
  288. * user_priority value "priority" matches these parameters if $low <= priority <= $high.
  289. *
  290. * If this parameter is specified for an entry, then Ethernet packets without IEEE 802.1Q encapsulation must not match this entry. If this
  291. * parameter is specified to an entry on a CM that does not support forwarding of IEEE 802.1Q encapsulated traffic, then this entry must
  292. * not be use for any traffic.
  293. *
  294. * @param int $low
  295. * @param int $high
  296. */
  297. function set_user_priority($low, $high)
  298. {
  299. if($low < 0 || $low > 7) trigger_error('User Priority Low must be 0 to 7', E_USER_WARNING);
  300. if($high < 0 || $high > 7) trigger_error('User Priority High must be 0 to 7', E_USER_WARNING);
  301. $this->value[DOCSIS_PACKET_CLASSIFIER_IEEE_USER_PRIORITY] =
  302. new docsis_encoder_string(DOCSIS_PACKET_CLASSIFIER_IEEE_USER_PRIORITY, chr($low) . chr($high));
  303. }
  304.  
  305. /**
  306. * Set IEEE 802.1Q VLAN_ID - docsis 1.1
  307. *
  308. * The value of the field specify the matching value for the IEEE 802.1Q vlan_id bits. Only the first (i.e., most-significant) 12 bits
  309. * of the specified vland_id field are significant; the final four bits must be ignored for comparison.
  310. *
  311. * If this parameter is specified for an entry, then Ethernet packets without IEEE 802.1Q encapsulation must not match this entry. If this
  312. * parameter is specified to an entry on a CM that does not support forwarding of IEEE 802.1Q encapsulated traffic, then this entry must
  313. * not be use for any traffic.
  314. *
  315. * @param $id
  316. */
  317. function set_vlan_id($id)
  318. {
  319. $this->value[DOCSIS_PACKET_CLASSIFIER_IEEE_VLAN_ID] = new docsis_encoder_ushort(DOCSIS_PACKET_CLASSIFIER_IEEE_VLAN_ID, $id);
  320. }
  321. }
  322.  
  323. /**
  324. * DOCSIS Packet Classifier
  325. *
  326. * @package docsis_config
  327. * @subpackage docsis_classifier
  328. */
  329. class docsis_packet_classifier extends docsis_encoder_complex
  330. {
  331. /**
  332. * Constructor
  333. *
  334. * @param int $code docsis code
  335. * @param array $value predefined values
  336. */
  337. function docsis_packet_classifier($code, $value=array())
  338. {
  339. parent::docsis_encoder_complex($code, $value);
  340. }
  341.  
  342. /**
  343. * Set Classifier Reference - docsis 1.1
  344. *
  345. * The value of the field specifies a reference for the Classifier. This value must be unique per Dynamic Service message, configuration
  346. * file, or Registration Request message.
  347. *
  348. * @param int $value
  349. */
  350. function set_reference($value)
  351. {
  352. if($value < 1 || $value > 255) trigger_error('Reference must be 1 to 255', E_USER_WARNING);
  353. $this->value[DOCSIS_PACKET_CLASSIFIER_REFERENCE] = new docsis_encoder_uchar(DOCSIS_PACKET_CLASSIFIER_REFERENCE, $value);
  354. }
  355.  
  356. /**
  357. * Set Classifier Identifier - docsis 1.1
  358. *
  359. * The value of the field specifies an identifier for the Classifier. This value must be unique per Service Flow. The CMTS assigns the
  360. * Packet Classifier Identifier.
  361. *
  362. * @param int $value
  363. */
  364. function set_identifier($value)
  365. {
  366. if($value < 1 || $value > 65535) trigger_error('Identifier must be 1 to 65535', E_USER_WARNING);
  367. $this->value[DOCSIS_PACKET_CLASSIFIER_IDENTIFIER] = new docsis_encoder_ushort(DOCSIS_PACKET_CLASSIFIER_IDENTIFIER, $value);
  368. }
  369.  
  370. /**
  371. * Set Service Flow Reference - docsis 1.1
  372. *
  373. * The value of the field specifies a Service Flow Reference that identifies the corresponding Service Flow.
  374. *
  375. * @param int $value
  376. */
  377. function set_flow_reference($value)
  378. {
  379. if($value < 1 || $value > 65535) trigger_error('Service Flow Reference must be 1 to 65535', E_USER_WARNING);
  380. $this->value[DOCSIS_PACKET_CLASSIFIER_FLOW_REFERENCE] = new docsis_encoder_ushort(DOCSIS_PACKET_CLASSIFIER_FLOW_REFERENCE, $value);
  381. }
  382.  
  383. /**
  384. * Set Service Flow Identifier - docsis 1.1
  385. *
  386. * The value of the field specifies the Service Flow ID that identifies the corresponding Service Flow.
  387. *
  388. * @param int $value
  389. */
  390. function set_flow_identifier($value)
  391. {
  392. if($value < 1 || $value > 4294967295) trigger_error('Service Flow Identifier must be 1 to 65535', E_USER_WARNING);
  393. $this->value[DOCSIS_PACKET_CLASSIFIER_FLOW_IDENTIFIER] = new docsis_encoder_uint(DOCSIS_PACKET_CLASSIFIER_FLOW_IDENTIFIER, $value);
  394. }
  395.  
  396. /**
  397. * Set Rule Priority - docsis 1.1
  398. *
  399. * The value of the field specifies the priority for the Classifier, which is used for determining the order of the Classifier. A higher
  400. * value indicates higher priority
  401. *
  402. * @param int $value
  403. */
  404. function set_rule_priority($value)
  405. {
  406. $this->value[DOCSIS_PACKET_CLASSIFIER_RULE_PRIORITY] = new docsis_encoder_uchar(DOCSIS_PACKET_CLASSIFIER_RULE_PRIORITY, $value);
  407. }
  408.  
  409. /**
  410. * Set Activation State - docsis 1.1
  411. *
  412. * @param boolean $value
  413. */
  414. function set_activation_state($value)
  415. {
  416. if($value < 0 || $value > 1) trigger_error('Activation State must be 0 or 1', E_USER_WARNING);
  417. $this->value[DOCSIS_PACKET_CLASSIFIER_ACTIVATION_STATE] = new docsis_encoder_uchar(DOCSIS_PACKET_CLASSIFIER_ACTIVATION_STATE, $value);
  418. }
  419.  
  420. /**
  421. * Set Dynamic Service Change Action - docsis 1.1
  422. *
  423. * 0: Add Classifier
  424. * 1: Replace Classifier
  425. * 2: Delete Classifier
  426. *
  427. * @param int $value
  428. */
  429. function set_dsc_action($value)
  430. {
  431. if($value < 0 || $value > 2) trigger_error('Activation State must be 0 or 1 or 2', E_USER_WARNING);
  432. $this->value[DOCSIS_PACKET_CLASSIFIER_DSC_ACTION] = new docsis_encoder_uchar(DOCSIS_PACKET_CLASSIFIER_DSC_ACTION, $value);
  433. }
  434.  
  435. /**
  436. * Set Error - docsis 1.1
  437. *
  438. * @param docsis_error $value
  439. */
  440. function set_error($value)
  441. {
  442. // todo: must be a docsis_error
  443. $this->value[DOCSIS_PACKET_CLASSIFIER_ERROR] = $value;
  444. }
  445.  
  446. /**
  447. * Set IP Packet Classifier - docsis 1.1
  448. *
  449. * @param docsis_ip_packet_classifier $value
  450. */
  451. function set_ip_packet_classifier($value)
  452. {
  453. // todo: must be a docsis_ip_packet_classifier
  454. $this->value[DOCSIS_PACKET_CLASSIFIER_IP_PACKET] = $value;
  455. }
  456.  
  457. /**
  458. * Set MAC Classifier - docsis 1.1
  459. *
  460. * @param docsis_ether_packet_classifier $value
  461. */
  462. function set_mac_classifier($value)
  463. {
  464. // todo: must be a docsis_ether_packet_classifier
  465. $this->value[DOCSIS_PACKET_CLASSIFIER_ETHERNET] = $value;
  466. }
  467.  
  468. /**
  469. * Set IEEE 802 Classifier - docsis 1.1
  470. *
  471. * @param docsis_ieee802_packet_classifier $value
  472. */
  473. function set_ieee802_classifier($value)
  474. {
  475. // todo: must be a docsis_ieee802_packet_classifier
  476. $this->value[DOCSIS_PACKET_CLASSIFIER_IEEE] = $value;
  477. }
  478.  
  479. /**
  480. * Set Vendor Specific Information - docsis 1.1
  481. *
  482. * @param docsis_vendor $value
  483. */
  484. function set_vendor($value)
  485. {
  486. // todo: must exist be a docsis_vendor
  487. $this->value[DOCSIS_VENDOR] = $value;
  488. }
  489. }
  490. ?>

Documentation generated on Mon, 14 Nov 2005 17:59:40 -0700 by phpDocumentor 1.3.0RC3