#include #include #include "snmp_pp/snmp_pp.h" #include "acl.h" #include "oids.h" #include "logger.h" using GTS::ACL; ACL::ACL(unsigned id, unsigned profileId, const std::string & mac, unsigned port, unsigned shape, unsigned burst, bool isUpload) : _id(id), _profileId(profileId), _mac(mac), _shape(shape), _burst(burst), _isUpload(isUpload) { port = 1 << (32 - port); _port = (boost::format("%|08x|") % port).str(); } ACL::ACL(const ACL & rvalue) : _id(rvalue._id), _profileId(rvalue._profileId), _mac(rvalue._mac), _port(rvalue._port), _shape(rvalue._shape), _burst(rvalue._burst), _isUpload(rvalue._isUpload) { } ACL::~ACL() { } ACL & ACL::operator=(const ACL & rvalue) { _id = rvalue._id; _profileId = rvalue._profileId; _mac = rvalue._mac; _port = rvalue._port; _shape = rvalue._shape; _burst = rvalue._burst; _isUpload = rvalue._isUpload; return *this; } void ACL::appendPdu(Pdu & pdu) const { std::string oidValue; // MAC if (_isUpload) { oidValue = swACLEtherRuleSrcMacAddress; oidValue += getSuffix(); } else { oidValue = swACLEtherRuleDstMacAddress; oidValue += getSuffix(); } Vb vb(Oid(oidValue.c_str())); vb.set_value(OctetStr::from_hex_string(_mac.c_str())); pdu += vb; // Permit rule oidValue = swACLEtherRulePermit; oidValue += getSuffix(); vb.set_oid(Oid(oidValue.c_str())); vb.set_value(int(2)); pdu += vb; // Port oidValue = swACLEtherRulePort; oidValue += getSuffix(); vb.set_oid(Oid(oidValue.c_str())); vb.set_value(OctetStr::from_hex_string(_port.c_str())); pdu += vb; // Shape oidValue = swACLEtherRuleRxRate; oidValue += getSuffix(); vb.set_oid(Oid(oidValue.c_str())); vb.set_value(int(_shape)); pdu += vb; // Create ACL oidValue = swACLEtherRuleRowStatus; oidValue += getSuffix(); vb.set_oid(Oid(oidValue.c_str())); vb.set_value(int(4)); pdu += vb; // Burst /*oidValue = swACLMeterBurstSize; oidValue += getSuffix(); vb.set_oid(Oid(oidValue.c_str())); vb.set_value(int(_burst)); pdu += vb;*/ } std::ostream & GTS::operator<<(std::ostream & stream, const ACL & acl) { std::string oidValue; // MAC if (acl._isUpload) { oidValue = swACLEtherRuleSrcMacAddress; oidValue += acl.getSuffix(); } else { oidValue = swACLEtherRuleDstMacAddress; oidValue += acl.getSuffix(); } stream << oidValue << " x " << acl._mac << " "; // Permit rule oidValue = swACLEtherRulePermit; oidValue += acl.getSuffix(); stream << oidValue << " i " << 2 << " "; // Port oidValue = swACLEtherRulePort; oidValue += acl.getSuffix(); stream << oidValue << " x " << acl._port << " "; // Shape oidValue = swACLEtherRuleRxRate; oidValue += acl.getSuffix(); stream << oidValue << " i " << acl._shape << " "; // Create ACL oidValue = swACLEtherRuleRowStatus; oidValue += acl.getSuffix(); stream << oidValue << " i " << 4; return stream; } inline std::string ACL::getSuffix() const { return std::string(".") + boost::lexical_cast(_profileId) + "." + boost::lexical_cast(_id); }