fix regex expression to find IPV4 address
[samplevnf.git] / VNFs / DPPD-PROX / helper-scripts / rapid / helper.lua
index d38bb80..a563340 100644 (file)
@@ -1,5 +1,5 @@
 --
--- Copyright (c) 2010-2020 Intel Corporation
+-- Copyright (c) 2020 Intel Corporation
 --
 -- Licensed under the Apache License, Version 2.0 (the "License");
 -- you may not use this file except in compliance with the License.
@@ -21,6 +21,22 @@ function convertIPToHex(ip)
     return "IP ADDRESS ERROR"
   end
 
+  local chunks = {ip:match("^(%d+)%.(%d+)%.(%d+)%.(%d+)(/%d+)$")}
+  if #chunks == 5 then
+    for i,v in ipairs(chunks) do
+      if i < 5 then
+        if tonumber(v) > 255 then
+          print ("IPV4 ADDRESS ERROR: ", ip)
+          return "IPV4 ADDRESS ERROR"
+        end
+        address_chunks[#address_chunks + 1] = string.format ("%02x", v)
+      end
+    end
+    result = table.concat(address_chunks, " ")
+    print ("Hex IPV4: ", result)
+    return result
+  end
+
   local chunks = {ip:match("^(%d+)%.(%d+)%.(%d+)%.(%d+)$")}
   if #chunks == 4 then
     for i,v in ipairs(chunks) do