Radius Example Analysis Agent

All decoding, validation, and manipulation are performed by the Analysis agent. The code logic is as follows:


  1. Each time the workflow is activated, a subscriber table is read into memory. To keep the example simple, the table content is assumed to be static. For a real implementation, it is recommended to re-read the table on a regular basis.
     

  2. Decode the UDP packet. Consider only UDRs of the type Default.extendedRadius.Access_Request_Int.
     

  3. Perform a lookup against the subscriber table, and create a reply of the type Default.extendedRadius.Access_Accept_Int or Default.extendedRadius.Access_Reject_Int, depending on whether the subscriber was found in the table.
     

  4. Route the reply back to the Radius agent.
     

table tmp_tab;

initialize {
  tmp_tab = tableCreate("select SUBSCRIBER from VALID_SUBSCRIBERS");
}


consume {
  list<drudr> reqList = listCreate(drudr);
  radius.Radius r = (radius.Radius) input;
  string err = udrDecode("Radius.Request_Dec", 
                           reqList, r.requestMessage, true);
   
  if ( (err != null) || (listSize(reqList) != 1) ) {
    debug("Decoding error: " + err);
    return;
  } 

  drudr elem = (drudr) listGet(reqList, 0);
  
  if (instanceOf(elem, Default.extendedRadius.Access_Request_Int)) {
        Default.extendedRadius.Access_Request_Int  req  = 
            (Default.extendedRadius.Access_Request_Int) elem;            
        table rowFound = tableLookup( tmp_tab, 
                         "SUBSCRIBER", "=", req.User_Name );
               
           if (tableRowCount(rowFound) > 0) {
             Default.extendedRadius.Access_Accept_Int   resp =
                    udrCreate(Default.extendedRadius.Access_Accept_Int);
             resp.Identifier = req.Identifier;
             r.responseMessage =
                    udrEncode("Default.extendedRadius.Response_Enc", resp);
              udrRoute( r );                 
           } else {
              Default.extendedRadius.Access_Reject_Int   resp =
                     udrCreate(Default.extendedRadius.Access_Reject_Int);
              resp.Identifier = req.Identifier;
              r.responseMessage =
                     udrEncode("Default.extendedRadius.Response_Enc", resp);
              udrRoute( r, "Response" );
           }
            
    } else {
       debug("Invalid request type");
    }
}