Today's the day. Renamed platform to framework.
This commit is contained in:
44
tmtcpacket/packetmatcher/ApidMatcher.h
Normal file
44
tmtcpacket/packetmatcher/ApidMatcher.h
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* ApidMatcher.h
|
||||
*
|
||||
* Created on: 09.03.2015
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#ifndef FRAMEWORK_TMTCPACKET_PACKETMATCHER_APIDMATCHER_H_
|
||||
#define FRAMEWORK_TMTCPACKET_PACKETMATCHER_APIDMATCHER_H_
|
||||
|
||||
#include <framework/globalfunctions/matching/SerializeableMatcherIF.h>
|
||||
#include <framework/serialize/SerializeAdapter.h>
|
||||
#include <framework/tmtcpacket/pus/TmPacketMinimal.h>
|
||||
|
||||
class ApidMatcher: public SerializeableMatcherIF<TmPacketMinimal*> {
|
||||
private:
|
||||
uint16_t apid;
|
||||
public:
|
||||
ApidMatcher(uint16_t setApid) :
|
||||
apid(setApid) {
|
||||
}
|
||||
bool match(TmPacketMinimal* packet) {
|
||||
if (packet->getAPID() == apid) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
ReturnValue_t serialize(uint8_t** buffer, uint32_t* size,
|
||||
const uint32_t max_size, bool bigEndian) const {
|
||||
return SerializeAdapter<uint16_t>::serialize(&apid, buffer, size, max_size, bigEndian);
|
||||
}
|
||||
uint32_t getSerializedSize() const {
|
||||
return SerializeAdapter<uint16_t>::getSerializedSize(&apid);
|
||||
}
|
||||
ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size,
|
||||
bool bigEndian) {
|
||||
return SerializeAdapter<uint16_t>::deSerialize(&apid, buffer, size, bigEndian);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* FRAMEWORK_TMTCPACKET_PACKETMATCHER_APIDMATCHER_H_ */
|
169
tmtcpacket/packetmatcher/PacketMatchTree.cpp
Normal file
169
tmtcpacket/packetmatcher/PacketMatchTree.cpp
Normal file
@ -0,0 +1,169 @@
|
||||
/*
|
||||
* PacketMatchTree.cpp
|
||||
*
|
||||
* Created on: 10.03.2015
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#include <framework/tmtcpacket/packetmatcher/ApidMatcher.h>
|
||||
#include <framework/tmtcpacket/packetmatcher/PacketMatchTree.h>
|
||||
#include <framework/tmtcpacket/packetmatcher/ServiceMatcher.h>
|
||||
#include <framework/tmtcpacket/packetmatcher/SubserviceMatcher.h>
|
||||
|
||||
PacketMatchTree::PacketMatchTree(Node* root) :
|
||||
MatchTree<TmPacketMinimal*>(root, 2), factoryBackend(0, POOL_SIZES,
|
||||
N_ELEMENTS, false, true), factory(&factoryBackend) {
|
||||
}
|
||||
|
||||
PacketMatchTree::PacketMatchTree(iterator root) :
|
||||
MatchTree<TmPacketMinimal*>(root.element, 2), factoryBackend(0,
|
||||
POOL_SIZES, N_ELEMENTS, false, true), factory(&factoryBackend) {
|
||||
}
|
||||
|
||||
PacketMatchTree::PacketMatchTree() :
|
||||
MatchTree<TmPacketMinimal*>((Node*) NULL, 2), factoryBackend(0,
|
||||
POOL_SIZES, N_ELEMENTS, false, true), factory(&factoryBackend) {
|
||||
}
|
||||
|
||||
PacketMatchTree::~PacketMatchTree() {
|
||||
}
|
||||
|
||||
ReturnValue_t PacketMatchTree::addMatch(uint16_t apid, uint8_t type,
|
||||
uint8_t subtype) {
|
||||
//We assume adding APID is always requested.
|
||||
uint8_t expectedHierarchy = 0;
|
||||
if (type != 0) {
|
||||
expectedHierarchy++;
|
||||
if (subtype != 0) {
|
||||
expectedHierarchy++;
|
||||
}
|
||||
}
|
||||
TmPacketMinimal::TmPacketMinimalPointer data;
|
||||
data.data_field.service_type = type;
|
||||
data.data_field.service_subtype = subtype;
|
||||
TmPacketMinimal testPacket((uint8_t*)&data);
|
||||
testPacket.setAPID(apid);
|
||||
uint8_t realHierarchy = 0;
|
||||
iterator lastMatch;
|
||||
bool isInTree = matchesTree(&testPacket, &lastMatch, &realHierarchy);
|
||||
if (isInTree) {
|
||||
//Matches somehow.
|
||||
//TODO: Are we interested in details?
|
||||
return RETURN_OK;
|
||||
}
|
||||
if (expectedHierarchy == realHierarchy) {
|
||||
//Add another element (of correct type) at the OR branch.
|
||||
lastMatch = addElement(OR, realHierarchy, lastMatch, &testPacket);
|
||||
if (lastMatch == this->end()) {
|
||||
return FULL;
|
||||
}
|
||||
} else if (expectedHierarchy > realHierarchy) {
|
||||
//A certain amount of downward structure does not exist. Add first element as OR, rest as AND.
|
||||
|
||||
lastMatch = addElement(OR, realHierarchy, lastMatch, &testPacket);
|
||||
if (lastMatch == end()) {
|
||||
return FULL;
|
||||
}
|
||||
iterator firstOfList = lastMatch;
|
||||
while (lastMatch != end() && realHierarchy < expectedHierarchy) {
|
||||
realHierarchy++;
|
||||
lastMatch = addElement(AND, realHierarchy, lastMatch, &testPacket);
|
||||
}
|
||||
if (lastMatch == end()) {
|
||||
//At least one element could not be inserted. So delete everything.
|
||||
removeElementAndAllChildren(firstOfList);
|
||||
return FULL;
|
||||
}
|
||||
} else {
|
||||
//Might work like that.
|
||||
//Too detailed match, delete the last element and all its children.
|
||||
while (lastMatch.up() != end() && lastMatch.up().left() != lastMatch) {
|
||||
lastMatch = lastMatch.up();
|
||||
}
|
||||
removeElementAndAllChildren(lastMatch);
|
||||
}
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t PacketMatchTree::removeMatch(uint16_t apid, uint8_t type,
|
||||
uint8_t subtype) {
|
||||
//We assume APID is always in request.
|
||||
uint8_t expectedHierarchy = 1;
|
||||
if (type != 0) {
|
||||
expectedHierarchy++;
|
||||
if (subtype != 0) {
|
||||
expectedHierarchy++;
|
||||
}
|
||||
}
|
||||
TmPacketMinimal::TmPacketMinimalPointer data;
|
||||
data.data_field.service_type = type;
|
||||
data.data_field.service_subtype = subtype;
|
||||
TmPacketMinimal testPacket((uint8_t*)&data);
|
||||
testPacket.setAPID(apid);
|
||||
uint8_t realHierarchy = 0;
|
||||
iterator lastMatch;
|
||||
bool isInTree = matchesTree(&testPacket, &lastMatch, &realHierarchy);
|
||||
if (isInTree) {
|
||||
if (expectedHierarchy == realHierarchy) {
|
||||
return removeElementAndReconnectChildren(lastMatch);
|
||||
} else {
|
||||
return TOO_DETAILED_REQUEST;
|
||||
}
|
||||
} else {
|
||||
//TODO: Maybe refine this a bit.
|
||||
return NO_MATCH;
|
||||
}
|
||||
}
|
||||
|
||||
PacketMatchTree::iterator PacketMatchTree::addElement(bool andBranch,
|
||||
uint8_t level, PacketMatchTree::iterator position,
|
||||
TmPacketMinimal* content) {
|
||||
SerializeableMatcherIF<TmPacketMinimal*>* newContent = NULL;
|
||||
switch (level) {
|
||||
case 0:
|
||||
newContent = factory.generate<ApidMatcher>(content->getAPID());
|
||||
break;
|
||||
case 1:
|
||||
newContent = factory.generate<ServiceMatcher>(content->getService());
|
||||
break;
|
||||
case 2:
|
||||
newContent = factory.generate<SubServiceMatcher>(
|
||||
content->getSubService());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (newContent == NULL) {
|
||||
return end();
|
||||
}
|
||||
Node* newNode = factory.generate<Node>(newContent);
|
||||
if (newNode == NULL) {
|
||||
return end();
|
||||
}
|
||||
return insert(andBranch, position, newNode);
|
||||
}
|
||||
|
||||
ReturnValue_t PacketMatchTree::initialize() {
|
||||
return factoryBackend.initialize();
|
||||
}
|
||||
|
||||
const uint16_t PacketMatchTree::POOL_SIZES[N_POOLS] = { sizeof(ServiceMatcher),
|
||||
sizeof(SubServiceMatcher), sizeof(ApidMatcher),
|
||||
sizeof(PacketMatchTree::Node) };
|
||||
//TODO: Rather arbitrary. Adjust!
|
||||
const uint16_t PacketMatchTree::N_ELEMENTS[N_POOLS] = { 10, 20, 2, 40 };
|
||||
|
||||
ReturnValue_t PacketMatchTree::changeMatch(bool addToMatch, uint16_t apid,
|
||||
uint8_t type, uint8_t subtype) {
|
||||
if (addToMatch) {
|
||||
return addMatch(apid, type, subtype);
|
||||
} else {
|
||||
return removeMatch(apid, type, subtype);
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t PacketMatchTree::cleanUpElement(iterator position) {
|
||||
//TODO: What if first deletion fails?
|
||||
factory.destroy(position.element->value);
|
||||
return factory.destroy(position.element);
|
||||
}
|
41
tmtcpacket/packetmatcher/PacketMatchTree.h
Normal file
41
tmtcpacket/packetmatcher/PacketMatchTree.h
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* PacketMatchTree.h
|
||||
*
|
||||
* Created on: 10.03.2015
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#ifndef FRAMEWORK_TMTCPACKET_PACKETMATCHER_PACKETMATCHTREE_H_
|
||||
#define FRAMEWORK_TMTCPACKET_PACKETMATCHER_PACKETMATCHTREE_H_
|
||||
|
||||
#include <framework/container/PlacementFactory.h>
|
||||
#include <framework/globalfunctions/matching/MatchTree.h>
|
||||
#include <framework/storagemanager/LocalPool.h>
|
||||
#include <framework/tmtcpacket/pus/TmPacketMinimal.h>
|
||||
|
||||
class PacketMatchTree: public MatchTree<TmPacketMinimal*>, public HasReturnvaluesIF {
|
||||
public:
|
||||
PacketMatchTree(Node* root);
|
||||
PacketMatchTree(iterator root);
|
||||
PacketMatchTree();
|
||||
virtual ~PacketMatchTree();
|
||||
ReturnValue_t changeMatch(bool addToMatch, uint16_t apid, uint8_t type = 0,
|
||||
uint8_t subtype = 0);
|
||||
ReturnValue_t addMatch(uint16_t apid, uint8_t type = 0,
|
||||
uint8_t subtype = 0);
|
||||
ReturnValue_t removeMatch(uint16_t apid, uint8_t type = 0,
|
||||
uint8_t subtype = 0);
|
||||
ReturnValue_t initialize();
|
||||
protected:
|
||||
ReturnValue_t cleanUpElement(iterator position);
|
||||
private:
|
||||
static const uint8_t N_POOLS = 4;
|
||||
LocalPool<N_POOLS> factoryBackend;
|
||||
PlacementFactory factory;
|
||||
static const uint16_t POOL_SIZES[N_POOLS];
|
||||
static const uint16_t N_ELEMENTS[N_POOLS];
|
||||
iterator addElement(bool andBranch, uint8_t level, iterator position, TmPacketMinimal* content);
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_TMTCPACKET_PACKETMATCHER_PACKETMATCHTREE_H_ */
|
||||
|
43
tmtcpacket/packetmatcher/ServiceMatcher.h
Normal file
43
tmtcpacket/packetmatcher/ServiceMatcher.h
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* ServiceMatcher.h
|
||||
*
|
||||
* Created on: 09.03.2015
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#ifndef FRAMEWORK_TMTCPACKET_PACKETMATCHER_SERVICEMATCHER_H_
|
||||
#define FRAMEWORK_TMTCPACKET_PACKETMATCHER_SERVICEMATCHER_H_
|
||||
|
||||
#include <framework/globalfunctions/matching/SerializeableMatcherIF.h>
|
||||
#include <framework/serialize/SerializeAdapter.h>
|
||||
#include <framework/tmtcpacket/pus/TmPacketMinimal.h>
|
||||
|
||||
class ServiceMatcher: public SerializeableMatcherIF<TmPacketMinimal*> {
|
||||
private:
|
||||
uint8_t service;
|
||||
public:
|
||||
ServiceMatcher(uint8_t setService) :
|
||||
service(setService) {
|
||||
}
|
||||
bool match(TmPacketMinimal* packet) {
|
||||
if (packet->getService() == service) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
ReturnValue_t serialize(uint8_t** buffer, uint32_t* size,
|
||||
const uint32_t max_size, bool bigEndian) const {
|
||||
return SerializeAdapter<uint8_t>::serialize(&service, buffer, size, max_size, bigEndian);
|
||||
}
|
||||
uint32_t getSerializedSize() const {
|
||||
return SerializeAdapter<uint8_t>::getSerializedSize(&service);
|
||||
}
|
||||
ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size,
|
||||
bool bigEndian) {
|
||||
return SerializeAdapter<uint8_t>::deSerialize(&service, buffer, size, bigEndian);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif /* FRAMEWORK_TMTCPACKET_PACKETMATCHER_SERVICEMATCHER_H_ */
|
44
tmtcpacket/packetmatcher/SubserviceMatcher.h
Normal file
44
tmtcpacket/packetmatcher/SubserviceMatcher.h
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* SubserviceMatcher.h
|
||||
*
|
||||
* Created on: 09.03.2015
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#ifndef FRAMEWORK_TMTCPACKET_PACKETMATCHER_SUBSERVICEMATCHER_H_
|
||||
#define FRAMEWORK_TMTCPACKET_PACKETMATCHER_SUBSERVICEMATCHER_H_
|
||||
|
||||
#include <framework/globalfunctions/matching/SerializeableMatcherIF.h>
|
||||
#include <framework/serialize/SerializeAdapter.h>
|
||||
#include <framework/tmtcpacket/pus/TmPacketMinimal.h>
|
||||
|
||||
class SubServiceMatcher: public SerializeableMatcherIF<TmPacketMinimal*> {
|
||||
public:
|
||||
SubServiceMatcher(uint8_t subService) :
|
||||
subService(subService) {
|
||||
}
|
||||
bool match(TmPacketMinimal* packet) {
|
||||
if (packet->getSubService() == subService) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
ReturnValue_t serialize(uint8_t** buffer, uint32_t* size,
|
||||
const uint32_t max_size, bool bigEndian) const {
|
||||
return SerializeAdapter<uint8_t>::serialize(&subService, buffer, size, max_size, bigEndian);
|
||||
}
|
||||
uint32_t getSerializedSize() const {
|
||||
return SerializeAdapter<uint8_t>::getSerializedSize(&subService);
|
||||
}
|
||||
ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size,
|
||||
bool bigEndian) {
|
||||
return SerializeAdapter<uint8_t>::deSerialize(&subService, buffer, size, bigEndian);
|
||||
}
|
||||
private:
|
||||
uint8_t subService;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* FRAMEWORK_TMTCPACKET_PACKETMATCHER_SUBSERVICEMATCHER_H_ */
|
Reference in New Issue
Block a user