ip: Replace Sematics for Interface IP addresses
[vpp.git] / src / plugins / cdp / cdp_node.c
index 1336c56..f9ee251 100644 (file)
@@ -23,7 +23,7 @@
 
     The interior node is neither pipelined nor dual-looped, because
     it would be very unusual to see more than one CDP packet in
-    a given input frame. So, it's a very simple / straighforward
+    a given input frame. So, it's a very simple / straightforward
     example.
 */
 
@@ -129,28 +129,7 @@ cdp_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f)
   f64 poll_time_remaining;
   uword event_type, *event_data = 0;
 
-  /* So we can send events to the cdp process */
-  cm->cdp_process_node_index = cdp_process_node.index;
-
-  /* Dynamically register the cdp input node with the snap classifier */
-  snap_register_input_protocol (vm, "cdp-input", 0xC /* ieee_oui, Cisco */ ,
-                               0x2000 /* protocol CDP */ ,
-                               cdp_input_node.index);
-
-  snap_register_input_protocol (vm, "cdp-input", 0xC /* ieee_oui, Cisco */ ,
-                               0x2004 /* protocol CDP */ ,
-                               cdp_input_node.index);
-
-#if 0                          /* retain for reference */
-  /* with the hdlc classifier */
-  hdlc_register_input_protocol (vm, HDLC_PROTOCOL_cdp, cdp_input_node.index);
-#endif
-
-  /* with ethernet input (for SRP) */
-  ethernet_register_input_type (vm, ETHERNET_TYPE_CDP /* CDP */ ,
-                               cdp_input_node.index);
-
-  /* Start w/ cdp effectively disabled */
+  /* Start w/ cdp disabled */
   poll_time_remaining = 86400.0;
 
   while (1)
@@ -166,6 +145,34 @@ cdp_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f)
          break;
 
        case CDP_EVENT_ENABLE:
+         if (!cm->cdp_protocol_registered)
+           {
+             /*
+              * Dynamically register the cdp input node
+              * with the snap classifier
+              */
+             snap_register_input_protocol (vm, "cdp-input",
+                                           0xC /* ieee_oui, Cisco */ ,
+                                           0x2000 /* protocol CDP */ ,
+                                           cdp_input_node.index);
+
+             snap_register_input_protocol (vm, "cdp-input",
+                                           0xC /* ieee_oui, Cisco */ ,
+                                           0x2004 /* protocol CDP */ ,
+                                           cdp_input_node.index);
+#if 0
+             /*
+              * Keep this code for reference...
+              * Register with the hdlc classifier
+              */
+             hdlc_register_input_protocol (vm, HDLC_PROTOCOL_cdp,
+                                           cdp_input_node.index);
+#endif
+             /* with ethernet input (for SRP) */
+             ethernet_register_input_type (vm, ETHERNET_TYPE_CDP /* CDP */ ,
+                                           cdp_input_node.index);
+             cm->cdp_protocol_registered = 1;
+           }
          poll_time_remaining = 10.0;
          break;
 
@@ -190,20 +197,17 @@ cdp_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f)
   return 0;
 }
 
-/*
- * cdp periodic node declaration
- */
-/* *INDENT-OFF* */
-VLIB_REGISTER_NODE (cdp_process_node) = {
-  .function = cdp_process,
-  .type = VLIB_NODE_TYPE_PROCESS,
-  .name = "cdp-process",
-};
-/* *INDENT-ON* */
-
 void
-vnet_cdp_node_reference (void)
+vnet_cdp_create_periodic_process (cdp_main_t * cmp)
 {
+  /* Already created the process node? */
+  if (cmp->cdp_process_node_index > 0)
+    return;
+
+  /* No, create it now and make a note of the node index */
+  cmp->cdp_process_node_index = vlib_process_create
+    (cmp->vlib_main, "cdp-process",
+     cdp_process, 16 /* log2_n_stack_bytes */ );
 }
 
 /*