CMTS.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. <?php
  2. namespace CablemodemBundle\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Gedmo\Mapping\Annotation as Gedmo;
  5. use JMS\Serializer\Annotation as JMS;
  6. use Symfony\Component\Validator\Constraints as Assert;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use Base\AdminBundle\Traits\TenancyIdTrait;
  9. use Base\AdminBundle\Traits\TenancyIdTraitInterface;
  10. use DeviceBundle\Interfaces\DeviceInterface;
  11. use DeviceBundle\Validator\Constraints as ValidatorAssert;
  12. use ExtraDataBundle\Entity\Traits\ExtraDataTrait;
  13. use Gedmo\SoftDeleteable\Traits\SoftDeleteableEntity as SoftDeleteable;
  14. use Base\AdminBundle\Interfaces\SoftDeleteInterface;
  15. use MapBundle\Entity\Interfaces\LocationInterface;
  16. use MapBundle\Entity\Traits\LocationTrait;
  17. /**
  18. * @ORM\Entity
  19. * @ORM\Table(indexes={@ORM\Index(name="host", columns={"host"})})
  20. *
  21. * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=true)
  22. *
  23. * @UniqueEntity(fields={"host"})
  24. *
  25. * @ValidatorAssert\Device
  26. */
  27. class CMTS implements DeviceInterface, TenancyIdTraitInterface, SoftDeleteInterface, LocationInterface
  28. {
  29. use ExtraDataTrait;
  30. use TenancyIdTrait;
  31. use SoftDeleteable;
  32. use LocationTrait;
  33. /**
  34. * @ORM\Column(name="id", type="bigint", nullable=false)
  35. * @ORM\Id
  36. * @ORM\GeneratedValue(strategy="IDENTITY")
  37. */
  38. protected $id;
  39. /**
  40. * @ORM\Column(type="string", length=50)
  41. *
  42. * @Assert\NotNull
  43. */
  44. protected $name;
  45. /**
  46. * @ORM\Column(type="string", unique=true, length=50, nullable=false)
  47. *
  48. * @Assert\NotNull
  49. * @Assert\NotBlank
  50. */
  51. protected $host;
  52. /**
  53. * @ORM\Column(type="string")
  54. *
  55. * @Assert\NotNull
  56. */
  57. protected $snmpCommunity;
  58. /**
  59. * @ORM\Column(type="integer")
  60. *
  61. * @Assert\NotNull
  62. */
  63. protected $snmpVersion;
  64. /**
  65. * @ORM\Column(type="boolean", nullable=true, columnDefinition="BOOLEAN DEFAULT TRUE")
  66. */
  67. protected $executeSnmp = true;
  68. /**
  69. * @ORM\Column(type="integer")
  70. *
  71. * @Assert\NotNull
  72. */
  73. protected $docsVersion;
  74. /**
  75. * @ORM\ManyToOne(targetEntity="CMTSModel", fetch="EXTRA_LAZY")
  76. *
  77. * @JMS\MaxDepth(1)
  78. */
  79. protected $model;
  80. /**
  81. * @ORM\Column(type="integer", options={"unsigned":true, "default":10})
  82. */
  83. protected $timeScan = 10;
  84. /**
  85. * @ORM\Column(type="integer", options={"unsigned":true, "default":5})
  86. */
  87. protected $timeCmtsOctets = 5;
  88. /**
  89. * @ORM\Column(type="integer", options={"unsigned":true, "default":10})
  90. */
  91. protected $timeCmStats = 10;
  92. /**
  93. * @return string
  94. */
  95. public function __toString()
  96. {
  97. return (string)$this->name;
  98. }
  99. /**
  100. * @return int
  101. */
  102. public function getId()
  103. {
  104. return $this->id;
  105. }
  106. /**
  107. * @return string
  108. */
  109. public function getName()
  110. {
  111. return $this->name;
  112. }
  113. /**
  114. * @return string
  115. */
  116. public function getHost()
  117. {
  118. return $this->host;
  119. }
  120. /**
  121. * @return string
  122. */
  123. public function getSnmpCommunity()
  124. {
  125. return $this->snmpCommunity;
  126. }
  127. /**
  128. * @return int
  129. */
  130. public function getSnmpVersion()
  131. {
  132. return $this->snmpVersion;
  133. }
  134. /**
  135. * @return boolean
  136. */
  137. public function getExecuteSnmp()
  138. {
  139. return $this->executeSnmp;
  140. }
  141. /**
  142. * @return CMTSModel
  143. */
  144. public function getModel()
  145. {
  146. return $this->model;
  147. }
  148. /**
  149. * @param string $name
  150. *
  151. * @return $this
  152. */
  153. public function setName($name)
  154. {
  155. $this->name = $name;
  156. return $this;
  157. }
  158. /**
  159. * @param string $host
  160. *
  161. * @return $this
  162. */
  163. public function setHost($host)
  164. {
  165. $this->host = $host;
  166. return $this;
  167. }
  168. /**
  169. * @param string $snmpCommunity
  170. *
  171. * @return $this
  172. */
  173. public function setSnmpCommunity($snmpCommunity)
  174. {
  175. $this->snmpCommunity = $snmpCommunity;
  176. return $this;
  177. }
  178. /**
  179. * @param int $snmpVersion
  180. *
  181. * @return $this
  182. */
  183. public function setSnmpVersion($snmpVersion)
  184. {
  185. $this->snmpVersion = $snmpVersion;
  186. return $this;
  187. }
  188. /**
  189. * @param boolean $executeSnmp
  190. *
  191. * @return $this
  192. */
  193. public function setExecuteSnmp($executeSnmp)
  194. {
  195. $this->executeSnmp = $executeSnmp;
  196. return $this;
  197. }
  198. /**
  199. * @param CMTSModel $model
  200. *
  201. * @return $this
  202. */
  203. public function setModel($model)
  204. {
  205. $this->model = $model;
  206. return $this;
  207. }
  208. /**
  209. * @return array
  210. */
  211. public function getDeviceData()
  212. {
  213. $extraData = [
  214. 'name' => $this->name,
  215. 'host' => $this->host,
  216. 'modelId' => $this->model ? $this->model->getId() : null,
  217. 'mark' => null,
  218. 'library' => null,
  219. 'snmpCommunity' => $this->snmpCommunity,
  220. 'snmpVersion' => $this->snmpVersion,
  221. 'docsVersion' => $this->docsVersion,
  222. 'executeSnmp' => $this->executeSnmp,
  223. 'timeScan' => $this->timeScan,
  224. 'timeCmtsOctets' => $this->timeCmtsOctets,
  225. 'timeCmStats' => $this->timeCmStats,
  226. ];
  227. if($this->model) {
  228. $extraData['mark'] = $this->model->getMark();
  229. $extraData['library'] = $this->model->getLibrary();
  230. }
  231. return [
  232. 'deviceType' => get_class($this),
  233. 'deviceId' => $this->id,
  234. 'ip' => $this->host,
  235. 'tenancy' => $this->tenancyId,
  236. 'extraData' => json_encode($extraData),
  237. ];
  238. }
  239. /**
  240. * @return array
  241. */
  242. public function getSoftDeleteCriteria()
  243. {
  244. return array('host' => $this->host);
  245. }
  246. /**
  247. * Set timeScan
  248. *
  249. * @param integer $timeScan
  250. */
  251. public function setTimeScan($timeScan)
  252. {
  253. $this->timeScan = $timeScan;
  254. }
  255. /**
  256. * Get timeScan
  257. *
  258. * @return integer
  259. */
  260. public function getTimeScan()
  261. {
  262. return $this->timeScan;
  263. }
  264. /**
  265. * Set timeCmtsOctets
  266. *
  267. * @param integer $timeCmtsOctets
  268. */
  269. public function setTimeCmtsOctets($timeCmtsOctets)
  270. {
  271. $this->timeCmtsOctets = $timeCmtsOctets;
  272. }
  273. /**
  274. * Get timeCmtsOctets
  275. *
  276. * @return integer
  277. */
  278. public function getTimeCmtsOctets()
  279. {
  280. return $this->timeCmtsOctets;
  281. }
  282. /**
  283. * Set timeCmStats
  284. *
  285. * @param integer $timeCmStats
  286. */
  287. public function setTimeCmStats($timeCmStats)
  288. {
  289. $this->timeCmStats = $timeCmStats;
  290. }
  291. /**
  292. * Get timeCmStats
  293. *
  294. * @return integer
  295. */
  296. public function getTimeCmStats()
  297. {
  298. return $this->timeCmStats;
  299. }
  300. /**
  301. * @return int
  302. */
  303. public function getDocsVersion()
  304. {
  305. return $this->docsVersion;
  306. }
  307. /**
  308. * @param int $docsVersion
  309. *
  310. * @return $this
  311. */
  312. public function setDocsVersion($docsVersion)
  313. {
  314. $this->docsVersion = $docsVersion;
  315. return $this;
  316. }
  317. }