Commit 7264a2fd authored by nikolajev's avatar nikolajev
Browse files

DiameterPort and Diameter Dissector update

parent 86f09350
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
#include "DiameterDispatcher.h"

DiameterDispatcher::DiameterDispatcher() 
  :Dispatcher("DIAMETER") {
  
}

DiameterDispatcher::~DiameterDispatcher() {

}
+21 −0
Original line number Diff line number Diff line
#ifndef DIAMETER_DISPATCHER_H
#define DIAMETER_DISPATCHER_H

#include "Helper/Singleton.h"
#include "Dispatcher.h"

class DiameterDispatcher : public Dispatcher, public Singleton<DiameterDispatcher> {
  
 protected:
  //Singleton
  DiameterDispatcher();
  
  //Singleton
  friend class Singleton<DiameterDispatcher>;

 public:
  ~DiameterDispatcher();

};

#endif
+104 −0
Original line number Diff line number Diff line
#include "DiameterDissector.h"
#include "Logger/Logger.h"
#include <boost/regex.hpp>

#include <iomanip>
#include <ios>
#include <iostream>
 
#include <stdlib.h>

DiameterDissector::DiameterDissector() :
	m_nMessageLength(HEADER_NOT_PARSED)
{
}

DiameterDissector::~DiameterDissector() 
{
}

DiameterDissector * DiameterDissector::Clone() const 
{
  return new DiameterDissector();
}

bool DiameterDissector::IsPacketValid() const
{
  return m_nMessageLength != PARSING_ERROR;
}

bool DiameterDissector::FinishDissection()
{
  if (m_nMessageLength == PARSING_ERROR) {
    return true;
  }
	// detect DIAMETER header
	const unsigned char * pData = GetPayload();
	unsigned int nLen = 0;
	std::cout << std::hex << std::setfill('0') << std::setw(2) << *pData << std::endl;
	if (m_nMessageLength == HEADER_NOT_PARSED)
	{
		if (*pData != 0x01) // Diameter version
		{
		  Logger::Instance().LogError("Invalid DIAMETER message, bad version number");
		  m_nMessageLength = PARSING_ERROR;
		  return true;
		}
		else
		{
		  m_nMessageLength = LENGTH_NOT_PARSED;
		  //pData += 1;
		  nLen = (*(unsigned int *)pData) & 0xFFFFFF00;
		  nLen = ((nLen &0x0000FF00)<<8) | ((nLen & 0x00FF0000) >> 8)|((nLen & 0xFF000000) >> 24);
		  std::cout << std::hex << std::setfill('0') << std::setw(2) << nLen << std::endl;
		}
	}
	if (m_nMessageLength == LENGTH_NOT_PARSED)
	{
	  m_nMessageLength = nLen;
	  std::cout << "DiameterDissector::FinishDissection: len= " << m_nMessageLength << std::endl;
	  pData += 4;
	  std::cout << std::hex << std::setfill('0') << std::setw(2) << *pData << std::endl;
	}

	return m_nMessageLength >= 0;
}


bool DiameterDissector::Dissect(const unsigned char * pData, const ssize_t nDataLength) 
{
	std::clog << ">>> DiameterDissector::Dissect: " << pData << std::endl;

  SavePayload(pData, nDataLength);
  return true;
}

bool DiameterDissector::NeedReassembly() const 
{
  return m_nMessageLength < 0 || m_nMessageLength > GetPayloadSize();
}

bool DiameterDissector::Reassemble(Dissector * pDissector, ProtocolInfo * pProtocolInfo) 
{
  if (!MatchProtocolInfo(pProtocolInfo)) {
    return false; // Different addresses or ports than expected
  }
  AppendPayload(pDissector);
  FinishDissection();
  return true;
}

const EProtocolType DiameterDissector::GetUpperLayerType() const 
{
  return EProtocolType_None;
}

ProtocolInfoElement * DiameterDissector::CreateLayerInfo()
{
	return 0;
}

bool DiameterDissector::CreatesUnprocessedData() const
{
  return true;
}
+32 −0
Original line number Diff line number Diff line
#ifndef DIAMETER_DISSECTOR_H
#define DIAMETER_DISSECTOR_H

#include "Dissector.h"
#include <string>

class DiameterDissector : public Dissector {

 public:
  DiameterDissector();
  virtual ~DiameterDissector();
  virtual DiameterDissector * Clone() const;
  virtual bool Dissect(const unsigned char * pData, const ssize_t nDataLen);
  virtual bool NeedReassembly() const;
  virtual bool Reassemble(Dissector * pDissector, ProtocolInfo * pProtocolInfo);
  virtual const EProtocolType GetUpperLayerType() const;
  virtual bool IsPacketValid() const;
  virtual bool FinishDissection();
  virtual bool CreatesUnprocessedData() const;
  virtual const EProtocolType GetDissectorType(){return EProtocolType_Diameter;}

 protected:
  ProtocolInfoElement * CreateLayerInfo();

 private:
  static const int HEADER_NOT_PARSED = -1;
  static const int LENGTH_NOT_PARSED = -2;
  static const int PARSING_ERROR = -3;
  int m_nMessageLength;
};

#endif
+2 −1
Original line number Diff line number Diff line
@@ -118,12 +118,13 @@ bool Dispatcher::Dispatch(DispatchInfo & info, ComponentFilter & filter) {

  // Transfer to upper layer
  const EProtocolType upperLayerType = pDissector->GetUpperLayerType();
  const EProtocolType dissectedDataType = pDissector->GetDissectorType();
	std::clog << "Dispatcher::Dispatch: UpperLayerType: " << upperLayerType << std::endl;
  
  bRes = false;
  if (upperLayerType == EProtocolType_None) // all headers have been removed
  {
	  filter.EnqueueMessage(info.GetData(), info.GetDataSize());
	  filter.EnqueueMessage(dissectedDataType, info.GetData(), info.GetDataSize());
	  std::stringstream ss;
	  ss << "Captured message enqueued to the TE (len " << info.GetDataSize() << ")";
      Logger::Instance().LogInfo(ss.str());
Loading