{"id":12935,"date":"2020-09-30T10:53:06","date_gmt":"2020-09-30T14:53:06","guid":{"rendered":"https:\/\/qxf2.com\/blog\/?p=12935"},"modified":"2020-09-30T10:53:06","modified_gmt":"2020-09-30T14:53:06","slug":"simulate-your-own-hardware-devices-as-templates-for-testing","status":"publish","type":"post","link":"https:\/\/qxf2.com\/blog\/simulate-your-own-hardware-devices-as-templates-for-testing\/","title":{"rendered":"Simulate your own hardware devices as templates for testing"},"content":{"rendered":"<p>This blog gives an idea to simulate your own devices by creating device templates. It would be helpful to QA or any user who has dependency with the device data for testing the application.<\/p>\n<p>Before getting into technical details about simulation, the following summary is about snmp and snmpwalk.<\/p>\n<h3>What is SNMP?<\/h3>\n<ul>\n<li>SNMP is a <strong>S<\/strong>imple <strong>N<\/strong>etwork <strong>M<\/strong>anagement <strong>P<\/strong>rotocol<strong>,<\/strong>\u00a0which is a simple set of operations (and the information these operations gather) that gives administrators the ability to change the state of some SNMP based device.<\/li>\n<li>The device can be a router, switch, printers, storage devices, Unix systems, Windows systems, power supplies, etc.<\/li>\n<\/ul>\n<h3>What is snmpwalk?<\/h3>\n<ul>\n<li>snmpwalk command facilitates the GETNEXT procedure for us.<\/li>\n<li>SNMP GETNEXT\u00a0<span>request to query for information on a network entity, the information could be of sysDescr or sysLocation, etc.<\/span><\/li>\n<li>Therefore snmpwalk is nothing but SNMP GETNEXT requests to query a network device for information until end of MIB is reached.<\/li>\n<\/ul>\n<hr \/>\n<p>We will do the following in this post:<\/p>\n<p>1. Enable SNMP configuration on the device<br \/>\n2. Create device templates<br \/>\n2.i. Using snmprec.py<br \/>\n2.ii. From .snmpwalk file<br \/>\n3. Run simulated SNMP device for the generated device template<\/p>\n<p>&nbsp;<\/p>\n<h4>1. Enable SNMP configuration on the device<\/h4>\n<p>We need to enable SNMP config on the device that you would like to simulate by creating a device template for it. Follow the instructions to achieve it.<\/p>\n<p>a) To enable SNMP configuration on the device we need to install snmp and snmpd.<\/p>\n<pre>sudo apt-get update\r\nsudo apt-get install snmp snmpd\r\n<\/pre>\n<p>b) Update snmpd.conf file<br \/>\nPlease note snmpd.conf file will be in <code>\/etc\/snmp\/snmpd.conf<\/code><\/p>\n<p>c) Open the daemon\u2019s configuration file with sudo privileges<\/p>\n<pre lang=\"python\">sudo vim snmpd.conf\r\necho agentAddress udp:127.0.0.1:161 &gt;&gt;\/etc\/snmp\/snmpd.conf<\/pre>\n<p>save the file.<\/p>\n<p>d) Restart the snmpd service<\/p>\n<pre lang=\"python\"> sudo service snmpd restart<\/pre>\n<p>e) Check if it&#8217;s working<\/p>\n<pre lang=\"python\">snmpwalk -v2c -c public localhost<\/pre>\n<p>Note: <span>here v2c refers to SNMP version 2, -c refers to the community string.<\/span><\/p>\n<p><a href=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/05\/snmpwalk.jpg\" data-rel=\"lightbox-image-0\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-12943\" src=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/05\/snmpwalk-300x184.jpg\" alt=\"snmpwalk example\" width=\"500\" height=\"307\" srcset=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/05\/snmpwalk-300x184.jpg 300w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/05\/snmpwalk-768x472.jpg 768w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/05\/snmpwalk-1024x629.jpg 1024w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/05\/snmpwalk.jpg 1567w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/a><\/p>\n<hr \/>\n<h3>2. Create device templates<\/h3>\n<p>Next, we will create device templates which requires installing snmpsim module and then create snmprec files using either Using snmprec.py or a .snmpwalk file.<\/p>\n<p>a) Install snmpsim python module using <code>pip<\/code><\/p>\n<pre lang=\"python\">pip install snmpsim<\/pre>\n<p>b) There are two ways to create device templates.<\/p>\n<ul><\/ul>\n<h4>i. Using snmprec.py<\/h4>\n<p>Here we will generate snmprec file by using <strong>snmprec.py<\/strong> tool of snmpsim python module and store the response data in a output snmprec file.<\/p>\n<pre lang=\"python\">snmprec.py --agent-udpv4-endpoint=127.0.0.1 --output-file=.\/local.snmprec<\/pre>\n<p>Note:-Execute the above command from your \/home\/ubuntu repository,\u00a0 otherwise it would give out\u00a0<span>permission denied error.<\/span><\/p>\n<p><a href=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/05\/snmprec.jpg\" data-rel=\"lightbox-image-1\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-12963\" src=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/05\/snmprec-300x39.jpg\" alt=\"Recording of the snmp data of the localhost\" width=\"600\" height=\"78\" srcset=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/05\/snmprec-300x39.jpg 300w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/05\/snmprec-768x99.jpg 768w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/05\/snmprec-1024x132.jpg 1024w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/05\/snmprec.jpg 1793w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p>After using the tool, a new\u00a0.snmprec file will be generated, depending upon the output file name given.<\/p>\n<p><a href=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/05\/local.jpg\" data-rel=\"lightbox-image-2\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-12964\" src=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/05\/local-300x186.jpg\" alt=\"snmprec file generated\" width=\"618\" height=\"383\" srcset=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/05\/local-300x186.jpg 300w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/05\/local-768x477.jpg 768w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/05\/local-1024x636.jpg 1024w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/05\/local.jpg 1588w\" sizes=\"auto, (max-width: 618px) 100vw, 618px\" \/><\/a><\/p>\n<hr \/>\n<h4>ii. From .snmpwalk file<\/h4>\n<p>Here we will generate .snmpwalk file and then convert that into a .snmprec file by using <strong>datafile.py<\/strong> tool of snmpsim Python module.<\/p>\n<p>To save the snmpwalk snapshot in a file use the below command<\/p>\n<pre lang=\"python\">snmpwalk -v2c -c public -ObentU localhost 1.3.6 &gt;&gt;localhost.snmpwalk<\/pre>\n<p>After this, a &#8220;<strong>localhost.snmpwalk<\/strong>&#8221; file will be generated which will contain the snmpwalk snapshot of the localhost. Next step is to convert the <strong>.snmpwalk<\/strong> file to <strong>.snmprec<\/strong> file by using <strong>datafile.py<\/strong> tool.<\/p>\n<pre lang=\"python\"> datafile.py --input-file=.\/localhost.snmpwalk --source-record-type=snmpwalk --output-file=.\/localhost.snmprec<\/pre>\n<p>Note:-Execute the above command from your \/home\/ubuntu repository,\u00a0 otherwise it would give out a\u00a0<span>permission denied error.<\/span><\/p>\n<p><a href=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/05\/datafile.py_.jpg\" data-rel=\"lightbox-image-3\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-12966\" src=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/05\/datafile.py_-300x100.jpg\" alt=\"conversion of datafile to .snmprec file.\" width=\"624\" height=\"208\" srcset=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/05\/datafile.py_-300x100.jpg 300w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/05\/datafile.py_-768x256.jpg 768w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/05\/datafile.py_-1024x342.jpg 1024w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/05\/datafile.py_.jpg 1896w\" sizes=\"auto, (max-width: 624px) 100vw, 624px\" \/><\/a><\/p>\n<hr \/>\n<h4>3. Run simulated SNMP device for the generated device template<\/h4>\n<p>To check if our device template is working or not, let&#8217;s do a test run.<\/p>\n<p>a) We will use SNMP Version 3<\/p>\n<pre lang=\"python\">snmpsimd.py --v3-engine-id=010203040505060880  --v3-user=qxf2  --data-dir=\/home\/ubuntu\/data  --agent-udpv4-endpoint=127.0.0.1:6464 &amp;<\/pre>\n<p><a href=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/05\/snmpv3.jpg\" data-rel=\"lightbox-image-4\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-12967\" src=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/05\/snmpv3-300x68.jpg\" alt=\"snmpsimd.py --v3-engine-id=010203040505060880 --v3-user=qxf2 --data-dir=\/home\/ubuntu\/data --agent-udpv4-endpoint=127.0.0.1:6464 &amp;\" width=\"994\" height=\"225\" srcset=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/05\/snmpv3-300x68.jpg 300w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/05\/snmpv3-768x175.jpg 768w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/05\/snmpv3-1024x233.jpg 1024w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/05\/snmpv3.jpg 1902w\" sizes=\"auto, (max-width: 994px) 100vw, 994px\" \/><\/a><\/p>\n<p>b) Let us see if the simulated device is responding.<\/p>\n<pre lang=\"python\"> snmpwalk -v2c -c localhost 127.0.0.1:6464<\/pre>\n<p>Note:\u00a0<strong>-c localhost<\/strong> is the community string &amp;\u00a0<strong>v2c<\/strong> is the SNMP version 2<br \/>\n<a href=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/05\/snmpwalk1.jpg\" data-rel=\"lightbox-image-5\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-12968\" src=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/05\/snmpwalk1-300x106.jpg\" alt=\"snmpwalk -v2c -c localhost 127.0.0.1:6464\" width=\"623\" height=\"220\" srcset=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/05\/snmpwalk1-300x106.jpg 300w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/05\/snmpwalk1-768x271.jpg 768w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/05\/snmpwalk1-1024x362.jpg 1024w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/05\/snmpwalk1.jpg 1902w\" sizes=\"auto, (max-width: 623px) 100vw, 623px\" \/><\/a><\/p>\n<hr \/>\n<p>I hope this blog helps you create hardware device templates for your testing purposes.<\/p>\n<p>For reference and more details on creating device templates:-<br \/>\n<a href=\"http:\/\/snmplabs.com\/snmpsim\/documentation\/building-simulation-data.html?\">Building simulation data<\/a><\/p>\n<p><a href=\"https:\/\/qxf2.com\/blog\/simulate-hardware-devices-and-switches-for-testing\/\" target=\"_blank\" rel=\"noopener\">simulate-hardware-devices-and-switches-for-testing<\/a><\/p>\n<hr \/>\n","protected":false},"excerpt":{"rendered":"<p>This blog gives an idea to simulate your own devices by creating device templates. It would be helpful to QA or any user who has dependency with the device data for testing the application. Before getting into technical details about simulation, the following summary is about snmp and snmpwalk. What is SNMP? SNMP is a Simple Network Management Protocol,\u00a0which is [&hellip;]<\/p>\n","protected":false},"author":30,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[208],"tags":[236],"class_list":["post-12935","post","type-post","status-publish","format-standard","hentry","category-snmpsim","tag-snmpsim"],"_links":{"self":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts\/12935","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/users\/30"}],"replies":[{"embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/comments?post=12935"}],"version-history":[{"count":100,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts\/12935\/revisions"}],"predecessor-version":[{"id":15581,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts\/12935\/revisions\/15581"}],"wp:attachment":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/media?parent=12935"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/categories?post=12935"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/tags?post=12935"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}