Policy > Networking > Network Services > Advanced Load Balancing > Alb Protocol Parsers

Create or update a ALBprotocolparser

If a ALBprotocolparser with the alb-protocolparser-id is not already present,
create a new ALBprotocolparser. If it already exists, update the
ALBprotocolparser. This is a full replace.
This API is only available when using VMware NSX-T.

Request:

Method:
PATCH
URI Path(s):
/policy/api/v1/infra/alb-protocol-parsers/<alb-protocolparser-id>
Request Headers:
n/a
Query Parameters:
n/a
Request Body:
ALBProtocolParser+

Example Request:

{ "name": "test-protocolParser", "parser_code": "#!/usr/bin/lua5.1\n\npackage.loaded.bitstring : nil\nlocal bitstring : require \"bitstring\"\n\nlocal parse_dhcp : {}\nlocal attribute_list : {}\nlocal dhcp_params : {}\nlocal ip_str : \"\"\nlocal dhcp_msg : \"\"\n\nlocal function _num_to_ipv4address(msg, start_pos)\n ip_str : \"\"\n local ip_len : 4\n while (ip_len >0) do\n temp : bitstring.unpack(\"8:int\", msg, start_pos)\n if (ip_len ~: 4) then\n ip_str : ip_str..\".\"\n end\n\n ip_str : ip_str..temp\n start_pos : start_pos + 1\n ip_len : ip_len - 1\n end\n\n return ip_str\nend\n\nlocal function _num_to_mac_address(msg, start_pos)\n mac_str : \"\"\n local mac_len : 6\n while (mac_len > 0) do\n temp : bitstring.unpack(\"8:int\", msg, start_pos)\n temp : string.format(\"%2.2X\", temp)\n if (mac_len ~: 6) then\n mac_str : mac_str .. \":\"\n end\n\n mac_str : mac_str .. temp\n start_pos : start_pos + 1\n mac_len : mac_len - 1\n end\n\n return mac_str\nend\n\nlocal function _get_key_value(dhcp_msg, option, attr_len, start_pos,end_pos)\n if option :: 53 then\n temp : bitstring.unpack(\"8:int\", dhcp_msg, start_pos, end_pos)\n elseif option :: 50 then\n temp : _num_to_ipv4address(dhcp_msg, start_pos)\n else\n if (#dhcp_msg < end_pos) then\n temp : bitstring.unpack(\"rest:bin\", dhcp_msg,\n start_pos, #dhcp_msg)\n else\n temp : bitstring.unpack((attr_len) .. \":bin, rest:bin\", dhcp_msg,\n start_pos, end_pos)\n end\n end\n return temp\nend\n\n\nfunction parse_dhcp_pkt(payload)\n dhcp_params : {}\n dhcp_msg : \"\"\n local pos : 1\n local result : {}\n local data : bitstring.hexstream(payload)\n dhcp_msg : bitstring.fromhexstream(data)\n\n -- parse radius message\n dhcp_params.msg_type, dhcp_params.hw_type, dhcp_params.hw_address_len, dhcp_params.hops, dhcp_params.txn_id, dhcp_params.elapsed_sec, dhcp_params.bootp_flags, dhcp_params.ciaddr, dhcp_params.yiaddr, dhcp_params.siaddr, dhcp_params.giaddr, dhcp_params.ch_mac, dhcp_params.client_hw_addr_padding,dhcp_params.sname, dhcp_params.boot_file, dhcp_params.dhcp_cookie : bitstring.unpack(\"8:int, 8:int, 8:int, 8:int, 32:int:big, 16:int:big, 2:bin, 4:bin, 4:bin, 4:bin, 4:bin, 6:bin, 10:bin, 64:bin, 128:bin, 4:bin\", dhcp_msg)\n\n\n if(bitstring.hexstream(dhcp_params.dhcp_cookie) ~: \"63825363\") then\n return false, \"DHCP parser (the magic cookie was invalid)\"\n end\n\n\n -- parse dhcp message\n attribute_list : {}\n local len : #dhcp_msg - 240\n local start_pos : 241\n local end_pos : 242\n local dictionary:{}\n\n while(len > 0) do\n if (len :: 1) then\n option: bitstring.unpack(\"8:int\", dhcp_msg, start_pos)\n -- Check for termination condition\n if (option :: 0xFF) then\n break,\n end\n break\n else\n option: bitstring.unpack(\"8:int\", dhcp_msg, start_pos, end_pos)\n end\n\n -- Check for termination condition\n if (option :: 0xFF) then\n break,\n end\n\n -- Option is of 1 Byte\n start_pos : start_pos + 1\n end_pos : end_pos + 1\n\n attr_length : bitstring.unpack(\"8:int\", dhcp_msg, start_pos)\n start_pos : start_pos + 1\n end_pos : start_pos + attr_length\n\n value : _get_key_value(dhcp_msg, option, attr_length, start_pos, end_pos)\n\n start_pos : end_pos\n len : len - attr_length - 2\n dictionary[tostring(option)] : value\n table.insert(attribute_list, {option : option, length : attr_length, value : value})\n end\n\n return dhcp_params, dictionary\nend\n\nfunction parse_dhcp.getDHCPParamsAndOptions(payload)\n dhcp_params, attribute_list : parse_dhcp_pkt(payload)\n return dhcp_params, attribute_list\nend\n\nfunction parse_dhcp.getOption61(dictionary)\n local option_val : dictionary['61']\n local eth_int : bitstring.unpack(\"8:int\", option_val, 1)\n local mac : _num_to_mac_address(option_val, 2)\n return eth_int, mac\nend\nreturn parse_dhcp" }

Successful Response:

Response Code:
200 OK
Response Headers:
n/a
Response Body:
n/a

Example Response:

200 OK

Required Permissions:

crud

Feature:

policy_lb

Additional Errors: