From d8a4cf75cdb009bf511b18f57ab6d080878c9e82 Mon Sep 17 00:00:00 2001 From: DanielJuravski Date: Wed, 7 Mar 2018 13:52:33 +0200 Subject: [PATCH 1/4] edited datainfo so it includes ipv4/6 address and ipv4/6 attached subnet + compatibility to rfc-8175 --- DataItem.h | 3 +- DestAdvert.cpp | 126 ++++++++++++++++++++++++++++++++++++-- DestAdvert.h | 22 +++++++ DestAdvertInfo.h | 36 ++++++++++- DestAdvertMessage.h | 82 ++++++++++++++++++++++++- Dlep.cpp | 4 +- DlepServiceImpl.cpp | 2 +- ExampleDlepClientImpl.cpp | 2 +- Peer.cpp | 64 +++++++++++++++++-- destadvert.proto | 4 ++ 10 files changed, 327 insertions(+), 18 deletions(-) diff --git a/DataItem.h b/DataItem.h index e6c84dc..9166e68 100644 --- a/DataItem.h +++ b/DataItem.h @@ -473,7 +473,8 @@ class DataItem const ProtocolConfig * protocfg; }; - +///shorthand for a vector of DataItem +typedef std::vector DataItems; } // namespace LLDLEP diff --git a/DestAdvert.cpp b/DestAdvert.cpp index 09b9203..b715ae1 100644 --- a/DestAdvert.cpp +++ b/DestAdvert.cpp @@ -62,7 +62,11 @@ DlepMessageBuffer DestAdvert::get_message_to_send(unsigned int * msg_len) time(NULL) - begin_time, // uptime ++seq_num, // seqnum local_rfid, // our radio id - destinations); // advertised destinations + destinations, // advertised destinations + localPeerIpv4DataItems, // advertised ipv4 dataitems + localPeerIpv4SnDataItems, // advertised ipv4 subnet dataitems + localPeerIpv6DataItems, // advertised ipv6 dataitems + localPeerIpv6SnDataItems);// advertised ipv6 subnet dataitems auto result = build_destination_advert(info); @@ -106,7 +110,7 @@ void DestAdvert::handle_message(DlepMessageBuffer msg_buffer, return; } - auto result = unbuild_destination_advert(msg_buffer.get(), msg_buffer_len); + auto result = unbuild_destination_advert(msg_buffer.get(), msg_buffer_len, dlep); if (! result.first) { @@ -132,14 +136,19 @@ void DestAdvert::handle_message(DlepMessageBuffer msg_buffer, LOG(DLEP_LOG_INFO, std::ostringstream("new destination advertisement entry!")); - DataItems empty_data_items; + // insert the ip data items to DataItems + DataItems dataItems = dainfo.ipv4DataItems; + dataItems.insert(dataItems.end(), dainfo.ipv4SnDataItems.begin(), dainfo.ipv4SnDataItems.end()); + dataItems.insert(dataItems.end(), dainfo.ipv6DataItems.begin(), dainfo.ipv6DataItems.end()); + dataItems.insert(dataItems.end(), dainfo.ipv6SnDataItems.begin(), dainfo.ipv6SnDataItems.end()); + // new entry, save timestamp and advertisement info dest_advert_db[dainfo.rfId] = DestAdvertDBEntry {time(NULL), DestAdvertDBEntry::EntryState::down, false, dainfo, - empty_data_items + dataItems }; } else @@ -191,6 +200,49 @@ void DestAdvert::handle_message(DlepMessageBuffer msg_buffer, // update the entry info to what was just received entry.info = dainfo; + + //update the entry info dataitems with ip dataitems that were just received + std::vector ipParameters = {dainfo.ipv4DataItems, dainfo.ipv4SnDataItems, dainfo.ipv6DataItems, dainfo.ipv6SnDataItems}; + for (auto dataItems : ipParameters) + { + DataItems ipdisAdd, ipdisRemove; + for (auto ipdi : dataItems) + { + DataItem::IPFlags ipAdded = ipdi.ip_flags(); + //if ip add, then we need to add all new and unique id data items + if (ipAdded == DataItem::IPFlags::add) + { + bool isNewIpDi = true; + for (auto di : entry.data_items) + { + if (di == ipdi) + { + isNewIpDi = false; + } + } + if (isNewIpDi) + { + //add only new ip dataitems + ipdisAdd.push_back(ipdi); + } + } + else //if ip drop remove this ip data item + { + for (auto di : entry.data_items) + { + if (ipdi.ip_equal(di)) + { + ipdisRemove.push_back(di); + } + } + } + } + entry.data_items.insert(entry.data_items.end(), ipdisAdd.begin(), ipdisAdd.end()); + for (auto ipdir : ipdisRemove) + { + entry.data_items.erase(std::remove(entry.data_items.begin(), entry.data_items.end(), ipdir), entry.data_items.end()); + } + } } } @@ -207,6 +259,39 @@ void DestAdvert::add_destination(const LLDLEP::DlepMac & mac) destinations.insert(mac); } +void DestAdvert::add_dataitem(const LLDLEP::DataItem & di) +{ + LOG(DLEP_LOG_INFO, std::ostringstream(di.to_string())); + + DataItems* selfDataItems(nullptr); + if (di.name() == ProtocolStrings::IPv4_Address) + { + selfDataItems = &localPeerIpv4DataItems; + }else if (di.name() == ProtocolStrings::IPv4_Attached_Subnet) + { + selfDataItems = &localPeerIpv4SnDataItems; + }else if (di.name() == ProtocolStrings::IPv6_Address) + { + selfDataItems = &localPeerIpv6DataItems; + }else if (di.name() == ProtocolStrings::IPv6_Attached_Subnet) + { + selfDataItems = &localPeerIpv6SnDataItems; + } + + DataItems ipdisRemove; + for (auto diRemove : *selfDataItems) + { + if (diRemove.ip_equal(di)) + { + ipdisRemove.push_back(diRemove); + } + } + for (auto diRemove : ipdisRemove) + { + selfDataItems->erase(std::remove(selfDataItems->begin(), selfDataItems->end(), diRemove), selfDataItems->end()); + } + selfDataItems->push_back(di); +} void DestAdvert::del_destination(const LLDLEP::DlepMac & mac) { @@ -289,7 +374,38 @@ DestAdvert::update_advert_entry_data_items(const DlepMac & rfId, if (iter != dest_advert_db.end()) { DestAdvertDBEntry & entry = iter->second; - entry.data_items = data_items; + DataItems ip_data_items; + //save aside all ip data items + for (auto di : entry.data_items) + { + if (di.name() == ProtocolStrings::IPv4_Address + || di.name() == ProtocolStrings::IPv4_Attached_Subnet + || di.name() == ProtocolStrings::IPv6_Address + || di.name() == ProtocolStrings::IPv6_Attached_Subnet) + { + ip_data_items.push_back(di); + msg << "updating ipdataitems=" << di.to_string(); + LOG(DLEP_LOG_INFO, msg); + } + } + + //clean entry + entry.data_items.erase(entry.data_items.begin(), entry.data_items.end()); + + //add all new data items wich are not ip + for (auto di : data_items) + { + if (di.name() != ProtocolStrings::IPv4_Address + && di.name() != ProtocolStrings::IPv4_Attached_Subnet + && di.name() != ProtocolStrings::IPv6_Address + && di.name() != ProtocolStrings::IPv6_Attached_Subnet) + { + entry.data_items.push_back(di); + } + } + + //add ip data items that we saved aside + entry.data_items.insert(entry.data_items.end(), ip_data_items.begin(), ip_data_items.end()); } else { diff --git a/DestAdvert.h b/DestAdvert.h index bc065e4..31f4a9e 100644 --- a/DestAdvert.h +++ b/DestAdvert.h @@ -58,6 +58,12 @@ class DestAdvert : public PeriodicMcastSendRcv /// @param[in] dest the destination to add void add_destination(const LLDLEP::DlepMac & dest); + /// Add a data item to future dataitems advertisements + /// sent by this process. + /// + /// @param[in] di the dataitem to add + void add_dataitem(const LLDLEP::DataItem & di); + /// Remove a destination from future destination advertisements /// sent by this process. /// @@ -134,6 +140,22 @@ class DestAdvert : public PeriodicMcastSendRcv /// including the peer router mac LLDLEP::DlepMacAddrs destinations; + /// any local ipv4 to put in destination advertisments, + /// including the peer router ipv4 + LLDLEP::DataItems localPeerIpv4DataItems; + + /// any local ipv4 subnet to put in destination advertisments, + /// including the peer router ipv4 subnet + LLDLEP::DataItems localPeerIpv4SnDataItems; + + /// any local ipv6 to put in destination advertisments, + /// including the peer router ipv6 + LLDLEP::DataItems localPeerIpv6DataItems; + + /// any local ipv6 subnet to put in destination advertisments, + /// including the peer router ipv6 subnet + LLDLEP::DataItems localPeerIpv6SnDataItems; + /// mutex that should be locked whenever dest_advert_db is accessed boost::recursive_mutex dest_advert_mutex; diff --git a/DestAdvertInfo.h b/DestAdvertInfo.h index a5edfd5..7924bad 100644 --- a/DestAdvertInfo.h +++ b/DestAdvertInfo.h @@ -30,6 +30,10 @@ struct DestAdvertInfo std::uint32_t sequenceNumber; LLDLEP::DlepMac rfId; LLDLEP::DlepMacAddrs destinations; + LLDLEP::DataItems ipv4DataItems; + LLDLEP::DataItems ipv4SnDataItems; + LLDLEP::DataItems ipv6DataItems; + LLDLEP::DataItems ipv6SnDataItems; DestAdvertInfo() : reportInterval {}, @@ -41,12 +45,20 @@ struct DestAdvertInfo time_t uptm, std::uint32_t seq, const LLDLEP::DlepMac & id, - const LLDLEP::DlepMacAddrs & dests) : + const LLDLEP::DlepMacAddrs & dest, + const LLDLEP::DataItems & ipv4Dis, + const LLDLEP::DataItems & ipv4SnDis, + const LLDLEP::DataItems & ipv6Dis, + const LLDLEP::DataItems & ipv6SnDis) : reportInterval {interval}, uptime {uptm}, sequenceNumber {seq}, rfId(id), - destinations(dests) + destinations(dest), + ipv4DataItems(ipv4Dis), + ipv4SnDataItems(ipv4SnDis), + ipv6DataItems(ipv6Dis), + ipv6SnDataItems(ipv6SnDis) { } std::string to_string() const @@ -64,6 +76,26 @@ struct DestAdvertInfo ss << dest.to_string() << ", "; } + for (auto ipdi : ipv4DataItems) + { + ss << ipdi.to_string() << ", "; + } + + for (auto ipdi : ipv4SnDataItems) + { + ss << ipdi.to_string() << ", "; + } + + for (auto ipdi : ipv6DataItems) + { + ss << ipdi.to_string() << ", "; + } + + for (auto ipdi : ipv6SnDataItems) + { + ss << ipdi.to_string() << ", "; + } + return ss.str(); } }; diff --git a/DestAdvertMessage.h b/DestAdvertMessage.h index 472e8cc..b1e5339 100644 --- a/DestAdvertMessage.h +++ b/DestAdvertMessage.h @@ -38,6 +38,30 @@ void doCopyMacToSTR(const LLDLEP::DlepMac & mac, std::string & str) str[i] = static_cast(mac.mac_addr[i]); } } + +void doCopyStrToIpdi(const std::string & str, LLDLEP::DataItem & ipdi) +{ + std::vector ipdi_ser; + ipdi_ser.resize(str.size()); + for (size_t i = 0; i < str.size(); i++) + { + ipdi_ser[i] = str[i]; + } + std::vector::const_iterator it = ipdi_ser.begin(); + std::vector::const_iterator it_end = ipdi_ser.end(); + + ipdi.deserialize(it, it_end); +} + +void doCopyIpdiToSTR(const LLDLEP::DataItem & ipdi, std::string & str) +{ + std::vector ipdi_ser = ipdi.serialize(); + str.resize(ipdi_ser.size()); + for (size_t i = 0; i < ipdi_ser.size(); ++i) + { + str[i] = static_cast(ipdi_ser[i]); + } +} } @@ -71,6 +95,34 @@ inline std::pair build_destination_advert( da.add_destinations(s); } + for (auto ipdi : info.ipv4DataItems) + { + std::string s; + doCopyIpdiToSTR(ipdi, s); + da.add_ipv4dataitems(s); + } + + for (auto ipdi : info.ipv4SnDataItems) + { + std::string s; + doCopyIpdiToSTR(ipdi, s); + da.add_ipv4sndataitems(s); + } + + for (auto ipdi : info.ipv6DataItems) + { + std::string s; + doCopyIpdiToSTR(ipdi, s); + da.add_ipv6dataitems(s); + } + + for (auto ipdi : info.ipv6SnDataItems) + { + std::string s; + doCopyIpdiToSTR(ipdi, s); + da.add_ipv6sndataitems(s); + } + const bool rc = da.SerializeToString(&str); return std::pair(rc, str); @@ -79,7 +131,7 @@ inline std::pair build_destination_advert( // un-build/de-serialize for reading inline std::pair unbuild_destination_advert( - const uint8_t * buff, size_t len) + const uint8_t * buff, size_t len, DlepPtr dlep) { DestAdvertInfo info; @@ -105,6 +157,34 @@ inline std::pair unbuild_destination_advert( info.destinations.insert(mac); } + + for (int i = 0; i < da.ipv4dataitems_size(); ++i) + { + DataItem ipdi(ProtocolStrings::IPv4_Address, dlep->protocfg); + doCopyStrToIpdi(da.ipv4dataitems(i), ipdi); + info.ipv4DataItems.push_back(ipdi); + } + + for (int i = 0; i < da.ipv4sndataitems_size(); ++i) + { + DataItem ipdi(ProtocolStrings::IPv4_Attached_Subnet, dlep->protocfg); + doCopyStrToIpdi(da.ipv4sndataitems(i), ipdi); + info.ipv4SnDataItems.push_back(ipdi); + } + + for (int i = 0; i < da.ipv6dataitems_size(); ++i) + { + DataItem ipdi(ProtocolStrings::IPv6_Address, dlep->protocfg); + doCopyStrToIpdi(da.ipv6dataitems(i), ipdi); + info.ipv6DataItems.push_back(ipdi); + } + + for (int i = 0; i < da.ipv6sndataitems_size(); ++i) + { + DataItem ipdi(ProtocolStrings::IPv6_Attached_Subnet, dlep->protocfg); + doCopyStrToIpdi(da.ipv6sndataitems(i), ipdi); + info.ipv6SnDataItems.push_back(ipdi); + } } return std::pair(rc, info); diff --git a/Dlep.cpp b/Dlep.cpp index c7b3a28..18dfd9b 100644 --- a/Dlep.cpp +++ b/Dlep.cpp @@ -164,8 +164,10 @@ Dlep::initialize() dlep_client.get_config_parameter("discovery-ttl", &discovery_ttl); } - catch (LLDLEP::DlepClient::BadParameterName) + //catch (LLDLEP::DlepClient::BadParameterName) + catch (const std::exception &e) { + std::cout<local_pdp->updateDestination(dest, data_items, true); + dlep->local_pdp->updateDestination(dest, entry.data_items, true); } } } diff --git a/ExampleDlepClientImpl.cpp b/ExampleDlepClientImpl.cpp index e46527a..e3082db 100644 --- a/ExampleDlepClientImpl.cpp +++ b/ExampleDlepClientImpl.cpp @@ -251,7 +251,7 @@ DlepClientImpl::ConfigParameterMapType DlepClientImpl::param_info = { "session-port", { ConfigParameterInfo::ParameterType::UnsignedInteger, - "854", + "4854", "TCP port number that the modem listens on for session connections" } }, diff --git a/Peer.cpp b/Peer.cpp index c9e19ef..68a0d2b 100644 --- a/Peer.cpp +++ b/Peer.cpp @@ -1122,7 +1122,11 @@ Peer::handle_peer_initialization(ProtocolMessage & pm) if (status_message != "") { - terminate(ProtocolStrings::Inconsistent_Data, status_message); + // following the RFC 8175 protocol (13.8.1), + // the receiver of inconsistent inforamtion MUST issue a Session + // Termination Message containing a Status Data Item with status set + // to 'Invalid Data' and transition to the Session Termination state. + terminate(ProtocolStrings::Invalid_Data, status_message); return; } @@ -1315,7 +1319,11 @@ Peer::handle_peer_update(ProtocolMessage & pm) if (status_message != "") { - terminate(ProtocolStrings::Inconsistent_Data, status_message); + // following the RFC 8175 protocol (13.8.1), + // the receiver of inconsistent inforamtion MUST issue a Session + // Termination Message containing a Status Data Item with status set + // to 'Invalid Data' and transition to the Session Termination state. + terminate(ProtocolStrings::Invalid_Data, status_message); return; } @@ -1324,6 +1332,13 @@ Peer::handle_peer_update(ProtocolMessage & pm) // We always send the update to the client, even if there was an error. // Is that OK? dlep->dlep_client.peer_update(peer_id, data_items); + if(dlep->dest_advert_enabled) + { + for (auto di : data_items) + { + dlep->dest_advert->add_dataitem(di); + } + } send_simple_response(ProtocolStrings::Session_Update_Response, update_status, ""); @@ -1389,8 +1404,15 @@ Peer::handle_destination_up(ProtocolMessage & pm) if (status_message != "") { - terminate(ProtocolStrings::Inconsistent_Data, status_message); - return; + // following the RFC 8175 protocol (13.8.1), + // MAY issue the appropriate response meesage containing Status Data Item + ostringstream msg; + msg << "peer=" << peer_id << " status=" << ProtocolStrings::Destination_Up_Response + << " reason=" << status_message; + LOG(DLEP_LOG_INFO, msg); + // following the RFC 8175 protocol, + // the receiver of inconsistent meesage MUST continue with session processing, + // therefore there is no place for 'return' } // If the peer had previously expressed Not Interested in @@ -1519,6 +1541,10 @@ Peer::handle_destination_announce(ProtocolMessage & pm) std::string response_name = dlep->protocfg->get_message_response_name(pm.get_signal_name()); + + msg << response_name; + LOG(DLEP_LOG_INFO, msg); + assert(response_name != ""); // already_have_this_dest will be true if we've already gotten a @@ -1528,6 +1554,12 @@ Peer::handle_destination_announce(ProtocolMessage & pm) bool already_have_this_dest = peer_pdp->validDestination(destination_mac); + msg << response_name << " response name"; + LOG(DLEP_LOG_INFO, msg); + + msg << already_have_this_dest << " already have this dest"; + LOG(DLEP_LOG_INFO, msg); + std::string statusname; if (! already_have_this_dest) { @@ -1559,8 +1591,15 @@ Peer::handle_destination_announce(ProtocolMessage & pm) // interacting with the client, and we're done. DestinationDataPtr ddp; + + msg << "gettting destination data"; + LOG(DLEP_LOG_INFO, msg); + if (dlep->local_pdp->getDestinationData(destination_mac, &ddp)) { + msg << " getting destination data YES"; + LOG(DLEP_LOG_INFO, msg); + DataItems response_data_items; ddp->get_all_data_items(response_data_items); @@ -1578,6 +1617,8 @@ Peer::handle_destination_announce(ProtocolMessage & pm) statusname = dlep->dlep_client.destination_up(peer_id, destination_mac, data_items); + msg << statusname << " status name"; + LOG(DLEP_LOG_INFO, msg); // convert empty status name to Success if (statusname == "") @@ -1587,6 +1628,10 @@ Peer::handle_destination_announce(ProtocolMessage & pm) } // destination did not already exist from this peer else { + msg << " What's the right status for a redudant Destination Announce?"; + msg << " destination already exists from this peer"; + LOG(DLEP_LOG_INFO, msg); + // What's the right status for a redundant Destination Announce? statusname = ProtocolStrings::Invalid_Message; } // destination already exists from this peer @@ -1632,8 +1677,15 @@ Peer::handle_destination_update(ProtocolMessage & pm) validate_ip_data_items(update_data_items, ddp->get_ip_data_items()); if (status_message != "") { - terminate(ProtocolStrings::Inconsistent_Data, status_message); - return; + // following the RFC 8175 protocol (13.8.1), + // MAY issue the appropriate response meesage containing Status Data Item + ostringstream msg; + msg << "peer=" << peer_id << " status=" << ProtocolStrings::Session_Update_Response + << " reason=" << status_message; + LOG(DLEP_LOG_INFO, msg); + // following the RFC 8175 protocol, + // the receiver of inconsistent meesage MUST continue with session processing, + // therefore there is no place for 'return' } ddp->update(update_data_items, false); diff --git a/destadvert.proto b/destadvert.proto index ecaf51f..32d74ef 100644 --- a/destadvert.proto +++ b/destadvert.proto @@ -4,5 +4,9 @@ message DestinationAdvertisement { required uint64 uptimeinseconds = 3; // application up time in seconds required bytes localid = 4; // our local modem/radio id repeated bytes destinations = 5; // destinations to advertise + repeated bytes ipv4dataitems = 6; // ipv4 data items to advertise + repeated bytes ipv4sndataitems = 7; // ipv4 subnet data items to advertise + repeated bytes ipv6dataitems = 8; // ipv6 data items to advertise + repeated bytes ipv6sndataitems = 9; // ipv6 subnet data items to advertise } From 37ea39f8573ac28fc2fe17b53490802b518302ff Mon Sep 17 00:00:00 2001 From: DanielJuravski Date: Wed, 7 Mar 2018 13:54:17 +0200 Subject: [PATCH 2/4] edited datainfo so it includes ipv4/6 address and ipv4/6 attached subnet + compatibility to rfc-8175 --- config/protocol/dlep-rfc-8175.xml | 92 ++++++++++++++++++++++++++++++- 1 file changed, 89 insertions(+), 3 deletions(-) diff --git a/config/protocol/dlep-rfc-8175.xml b/config/protocol/dlep-rfc-8175.xml index c2fc953..953ecfb 100644 --- a/config/protocol/dlep-rfc-8175.xml +++ b/config/protocol/dlep-rfc-8175.xml @@ -157,7 +157,7 @@ This protocol configuration file conforms to DLEP RFC 8175. - Relative_Link_Quality_Receive + Resources_Receive u8 18 true @@ -165,17 +165,33 @@ This protocol configuration file conforms to DLEP RFC 8175. - Relative_Link_Quality_Transmit + Resources_Transmit u8 19 true percentage + + Relative_Link_Quality_Receive + u8 + 20 + true + percentage + + + + Relative_Link_Quality_Transmit + u8 + 21 + true + percentage + + Maximum_Transmission_Unit u16 - 20 + 22 true octets @@ -268,6 +284,16 @@ This protocol configuration file conforms to DLEP RFC 8175. 0-1 + + Resources_Receive + 0-1 + + + + Resources_Transmit + 0-1 + + Relative_Link_Quality_Receive 0-1 @@ -421,6 +447,16 @@ This protocol configuration file conforms to DLEP RFC 8175. 0-1 + + Resources_Receive + 0-1 + + + + Resources_Transmit + 0-1 + + Relative_Link_Quality_Receive 0-1 @@ -516,6 +552,16 @@ This protocol configuration file conforms to DLEP RFC 8175. 0-1 + + Resources_Receive + 0-1 + + + + Resources_Transmit + 0-1 + + Relative_Link_Quality_Receive 0-1 @@ -593,6 +639,16 @@ This protocol configuration file conforms to DLEP RFC 8175. 0-1 + + Resources_Receive + 0-1 + + + + Resources_Transmit + 0-1 + + Relative_Link_Quality_Receive 0-1 @@ -654,6 +710,16 @@ This protocol configuration file conforms to DLEP RFC 8175. IPv6_Address 0+ + + + IPv4_Attached_Subnet + 0+ + + + + IPv6_Attached_Subnet + 0+ + @@ -727,6 +793,16 @@ This protocol configuration file conforms to DLEP RFC 8175. 0-1 + + Resources_Receive + 0-1 + + + + Resources_Transmit + 0-1 + + Relative_Link_Quality_Receive 0-1 @@ -804,6 +880,16 @@ This protocol configuration file conforms to DLEP RFC 8175. 0-1 + + Resources_Receive + 0-1 + + + + Resources_Transmit + 0-1 + + Relative_Link_Quality_Receive 0-1 From 617def9e02bdaed5eb86ed52a6d82e97c985d509 Mon Sep 17 00:00:00 2001 From: DanielJuravski Date: Wed, 14 Mar 2018 10:35:10 +0200 Subject: [PATCH 3/4] bug fixed on session termination bug fixed on: 1. on session termination in modem, local dataitems related to router need to be cleared. 2. in destination advertisement, whet destination is no longer advertised by remote modem, its ipdataitems need to be removed. --- DestAdvert.cpp | 138 +++++++++++++++++++++++++------------- DestAdvert.h | 10 +++ DestAdvertInfo.h | 20 +++--- Dlep.cpp | 4 +- DlepServiceImpl.cpp | 4 ++ ExampleDlepClientImpl.cpp | 2 +- Peer.cpp | 18 ++++- 7 files changed, 136 insertions(+), 60 deletions(-) diff --git a/DestAdvert.cpp b/DestAdvert.cpp index b715ae1..b610e35 100644 --- a/DestAdvert.cpp +++ b/DestAdvert.cpp @@ -161,7 +161,7 @@ void DestAdvert::handle_message(DlepMessageBuffer msg_buffer, // update timestamp entry.timestamp = time(NULL); - + //entry.data_items.clear(); if (entry.estate == DestAdvertDBEntry::EntryState::up) { DlepMacAddrs added, deleted; @@ -172,6 +172,17 @@ void DestAdvert::handle_message(DlepMessageBuffer msg_buffer, getDifference(dainfo.destinations, entry.info.destinations, added); + msg << "added size " << added.size(); + for (auto it = dainfo.destinations.begin(); it != dainfo.destinations.end(); ++it) + { + msg << " dainfo.destinations" << *it; + } + for (auto it = entry.info.destinations.begin(); it != entry.info.destinations.end(); ++it) + { + msg << " entry.info.destinations" << *it; + } + LOG(DLEP_LOG_DEBUG, msg); + for (const DlepMac & mac : added) { if (! dlep->local_pdp->addDestination(mac, entry.data_items, @@ -182,14 +193,62 @@ void DestAdvert::handle_message(DlepMessageBuffer msg_buffer, } } + //update the entry info dataitems with ip dataitems that were just received + std::vector ipParameters = {dainfo.ipv4DataItems, dainfo.ipv4SnDataItems, dainfo.ipv6DataItems, dainfo.ipv6SnDataItems}; + for (auto dataItems : ipParameters) + { + DataItems ipdisAdd, ipdisRemove; + for (auto ipdi : dataItems) + { + DataItem::IPFlags ipAdded = ipdi.ip_flags(); + //if ip add, then we need to add all new and unique id data items + if (ipAdded == DataItem::IPFlags::add) + { + bool isNewIpDi = true; + for (auto di : entry.data_items) + { + if (di == ipdi) + { + isNewIpDi = false; + } + } + if (isNewIpDi) + { + //add only new ip dataitems + ipdisAdd.push_back(ipdi); + } + } + else //if ip drop remove this ip data item + { + for (auto di : entry.data_items) + { + if (ipdi.ip_equal(di)) + { + ipdisRemove.push_back(di); + } + } + } + } + entry.data_items.insert(entry.data_items.end(), ipdisAdd.begin(), ipdisAdd.end()); + for (auto ipdir : ipdisRemove) + { + entry.data_items.erase(std::remove(entry.data_items.begin(), entry.data_items.end(), ipdir), entry.data_items.end()); + } + } + // handle destinations that were deleted by this advertisement // old - new = deleted getDifference(entry.info.destinations, dainfo.destinations, deleted); + msg << "deleted size " << deleted.size(); + LOG(DLEP_LOG_DEBUG, msg); + + for (const DlepMac & mac : deleted) { + entry.data_items.clear(); if (! dlep->local_pdp->removeDestination(mac, true)) { msg << "destination " << mac << " does not exist"; @@ -197,52 +256,8 @@ void DestAdvert::handle_message(DlepMessageBuffer msg_buffer, } } } - // update the entry info to what was just received entry.info = dainfo; - - //update the entry info dataitems with ip dataitems that were just received - std::vector ipParameters = {dainfo.ipv4DataItems, dainfo.ipv4SnDataItems, dainfo.ipv6DataItems, dainfo.ipv6SnDataItems}; - for (auto dataItems : ipParameters) - { - DataItems ipdisAdd, ipdisRemove; - for (auto ipdi : dataItems) - { - DataItem::IPFlags ipAdded = ipdi.ip_flags(); - //if ip add, then we need to add all new and unique id data items - if (ipAdded == DataItem::IPFlags::add) - { - bool isNewIpDi = true; - for (auto di : entry.data_items) - { - if (di == ipdi) - { - isNewIpDi = false; - } - } - if (isNewIpDi) - { - //add only new ip dataitems - ipdisAdd.push_back(ipdi); - } - } - else //if ip drop remove this ip data item - { - for (auto di : entry.data_items) - { - if (ipdi.ip_equal(di)) - { - ipdisRemove.push_back(di); - } - } - } - } - entry.data_items.insert(entry.data_items.end(), ipdisAdd.begin(), ipdisAdd.end()); - for (auto ipdir : ipdisRemove) - { - entry.data_items.erase(std::remove(entry.data_items.begin(), entry.data_items.end(), ipdir), entry.data_items.end()); - } - } } } @@ -293,6 +308,14 @@ void DestAdvert::add_dataitem(const LLDLEP::DataItem & di) selfDataItems->push_back(di); } +void DestAdvert::clear_ipdataitems() +{ + localPeerIpv4DataItems.erase(localPeerIpv4DataItems.begin(), localPeerIpv4DataItems.end()); + localPeerIpv4SnDataItems.erase(localPeerIpv4SnDataItems.begin(), localPeerIpv4SnDataItems.end()); + localPeerIpv6DataItems.erase(localPeerIpv6DataItems.begin(), localPeerIpv6DataItems.end()); + localPeerIpv6SnDataItems.erase(localPeerIpv6SnDataItems.begin(), localPeerIpv6SnDataItems.end()); +} + void DestAdvert::del_destination(const LLDLEP::DlepMac & mac) { LOG(DLEP_LOG_INFO, std::ostringstream(mac.to_string())); @@ -414,6 +437,31 @@ DestAdvert::update_advert_entry_data_items(const DlepMac & rfId, } } +void +DestAdvert::clear_advert_entry_data_items(const DlepMac & rfId) +{ + boost::recursive_mutex::scoped_lock lock(dest_advert_mutex); + std::ostringstream msg; + + msg << "clearing dataitems of rfid=" << rfId.to_string(); + LOG(DLEP_LOG_INFO, msg); + + const auto iter = dest_advert_db.find(rfId); + + if (iter != dest_advert_db.end()) + { + DestAdvertDBEntry & entry = iter->second; + + entry.data_items.clear(); + entry.data_items.erase(entry.data_items.begin(), entry.data_items.end()); + } + else + { + msg << "rfid " << rfId.to_string() << " not found in table"; + LOG(DLEP_LOG_ERROR, msg); + } +} + void DestAdvert::update_advert_entry_state(const DlepMac & rfId, DestAdvertDBEntry::EntryState newstate) diff --git a/DestAdvert.h b/DestAdvert.h index 31f4a9e..781c8f0 100644 --- a/DestAdvert.h +++ b/DestAdvert.h @@ -64,6 +64,10 @@ class DestAdvert : public PeriodicMcastSendRcv /// @param[in] di the dataitem to add void add_dataitem(const LLDLEP::DataItem & di); + /// Remove all ipdataitems from future destination advertisements + /// sent by this process. + void clear_ipdataitems(); + /// Remove a destination from future destination advertisements /// sent by this process. /// @@ -101,6 +105,12 @@ class DestAdvert : public PeriodicMcastSendRcv void update_advert_entry_data_items(const LLDLEP::DlepMac & rfId, const LLDLEP::DataItems & data_items); + /// Clear the metrics on an entry in the destination advertisement + /// database. + /// @param[in] rfId the RF_ID whose entry will be updated + /// @param[in] data_items the data items associated with rfId + void clear_advert_entry_data_items(const LLDLEP::DlepMac & rfId); + /// Update the state of an entry in the destination advertisement /// database. /// @param[in] rfId the RF_ID whose entry will be updated diff --git a/DestAdvertInfo.h b/DestAdvertInfo.h index 7924bad..96ee7ae 100644 --- a/DestAdvertInfo.h +++ b/DestAdvertInfo.h @@ -45,20 +45,20 @@ struct DestAdvertInfo time_t uptm, std::uint32_t seq, const LLDLEP::DlepMac & id, - const LLDLEP::DlepMacAddrs & dest, - const LLDLEP::DataItems & ipv4Dis, - const LLDLEP::DataItems & ipv4SnDis, - const LLDLEP::DataItems & ipv6Dis, - const LLDLEP::DataItems & ipv6SnDis) : + const LLDLEP::DlepMacAddrs & dests, + const LLDLEP::DataItems & ipv4Dest, + const LLDLEP::DataItems & ipv4SnDest, + const LLDLEP::DataItems & ipv6Dest, + const LLDLEP::DataItems & ipv6SnDest) : reportInterval {interval}, uptime {uptm}, sequenceNumber {seq}, rfId(id), - destinations(dest), - ipv4DataItems(ipv4Dis), - ipv4SnDataItems(ipv4SnDis), - ipv6DataItems(ipv6Dis), - ipv6SnDataItems(ipv6SnDis) + destinations(dests), + ipv4DataItems(ipv4Dest), + ipv4SnDataItems(ipv4SnDest), + ipv6DataItems(ipv6Dest), + ipv6SnDataItems(ipv6SnDest) { } std::string to_string() const diff --git a/Dlep.cpp b/Dlep.cpp index 18dfd9b..c7b3a28 100644 --- a/Dlep.cpp +++ b/Dlep.cpp @@ -164,10 +164,8 @@ Dlep::initialize() dlep_client.get_config_parameter("discovery-ttl", &discovery_ttl); } - //catch (LLDLEP::DlepClient::BadParameterName) - catch (const std::exception &e) + catch (LLDLEP::DlepClient::BadParameterName) { - std::cout<local_pdp->updateDestination(dest, entry.data_items, true); @@ -201,6 +203,8 @@ DlepServiceImpl::destination_down(const DlepMac & mac_address) auto result = dlep->dest_advert->find_advert_entry(mac_address); + //dlep->dest_advert->clear_advert_entry_data_items(mac_address); + if (result.first) { dest_down_mac_address = false; diff --git a/ExampleDlepClientImpl.cpp b/ExampleDlepClientImpl.cpp index e3082db..e46527a 100644 --- a/ExampleDlepClientImpl.cpp +++ b/ExampleDlepClientImpl.cpp @@ -251,7 +251,7 @@ DlepClientImpl::ConfigParameterMapType DlepClientImpl::param_info = { "session-port", { ConfigParameterInfo::ParameterType::UnsignedInteger, - "4854", + "854", "TCP port number that the modem listens on for session connections" } }, diff --git a/Peer.cpp b/Peer.cpp index 68a0d2b..24433df 100644 --- a/Peer.cpp +++ b/Peer.cpp @@ -595,7 +595,7 @@ Peer::destination_down(const DlepMac & destination_mac) msg << "to peer=" << peer_id << " destination mac=" << destination_mac; LOG(DLEP_LOG_INFO, msg); - + //dlep->dest_advert->clear_advert_entry_data_items(destination_mac); ProtocolMessage pm {dlep->protocfg, dlep->logger}; pm.add_header(ProtocolStrings::Destination_Down); @@ -826,6 +826,7 @@ Peer::terminate(const std::string & status_name, const std::string & reason) return; } + dlep->dest_advert->clear_ipdataitems(); stop_peer(); // Create and serialize a Termination message @@ -1334,6 +1335,7 @@ Peer::handle_peer_update(ProtocolMessage & pm) dlep->dlep_client.peer_update(peer_id, data_items); if(dlep->dest_advert_enabled) { + //when there is peer update, publish the dataitems to the others modems for (auto di : data_items) { dlep->dest_advert->add_dataitem(di); @@ -1410,6 +1412,19 @@ Peer::handle_destination_up(ProtocolMessage & pm) msg << "peer=" << peer_id << " status=" << ProtocolStrings::Destination_Up_Response << " reason=" << status_message; LOG(DLEP_LOG_INFO, msg); + + //ProtocolMessage pm {dlep->protocfg, dlep->logger}; + + //pm.add_header(ProtocolStrings::Destination_Up_Response); + //pm.add_status(ProtocolStrings::Inconsistent_Data, status_message); + + // A freshly built message should be parsable. + + //std::string err = pm.parse_and_validate(dlep->is_modem(), __func__); + + //ResponsePendingPtr rp(new ResponsePending(dlep->protocfg, pm)); + //send_message_expecting_response(rp); + // following the RFC 8175 protocol, // the receiver of inconsistent meesage MUST continue with session processing, // therefore there is no place for 'return' @@ -2067,6 +2082,7 @@ Peer::set_state_terminating() { // clear all destinations associated with this peer dlep->dest_advert->clear_destinations(); + dlep->dest_advert->clear_ipdataitems(); } } } From 91d7aebe0fb7c2df2cc9a149a8109ce11e7f6a33 Mon Sep 17 00:00:00 2001 From: DanielJuravski Date: Wed, 14 Mar 2018 16:56:22 +0200 Subject: [PATCH 4/4] code cleanup --- DestAdvert.cpp | 26 -------------------------- DestAdvert.h | 6 ------ DestAdvertMessage.h | 2 ++ DlepServiceImpl.cpp | 6 ++---- Peer.cpp | 41 ++++++++++++++++------------------------- 5 files changed, 20 insertions(+), 61 deletions(-) diff --git a/DestAdvert.cpp b/DestAdvert.cpp index b610e35..c2cad77 100644 --- a/DestAdvert.cpp +++ b/DestAdvert.cpp @@ -161,7 +161,6 @@ void DestAdvert::handle_message(DlepMessageBuffer msg_buffer, // update timestamp entry.timestamp = time(NULL); - //entry.data_items.clear(); if (entry.estate == DestAdvertDBEntry::EntryState::up) { DlepMacAddrs added, deleted; @@ -437,31 +436,6 @@ DestAdvert::update_advert_entry_data_items(const DlepMac & rfId, } } -void -DestAdvert::clear_advert_entry_data_items(const DlepMac & rfId) -{ - boost::recursive_mutex::scoped_lock lock(dest_advert_mutex); - std::ostringstream msg; - - msg << "clearing dataitems of rfid=" << rfId.to_string(); - LOG(DLEP_LOG_INFO, msg); - - const auto iter = dest_advert_db.find(rfId); - - if (iter != dest_advert_db.end()) - { - DestAdvertDBEntry & entry = iter->second; - - entry.data_items.clear(); - entry.data_items.erase(entry.data_items.begin(), entry.data_items.end()); - } - else - { - msg << "rfid " << rfId.to_string() << " not found in table"; - LOG(DLEP_LOG_ERROR, msg); - } -} - void DestAdvert::update_advert_entry_state(const DlepMac & rfId, DestAdvertDBEntry::EntryState newstate) diff --git a/DestAdvert.h b/DestAdvert.h index 781c8f0..498672c 100644 --- a/DestAdvert.h +++ b/DestAdvert.h @@ -105,12 +105,6 @@ class DestAdvert : public PeriodicMcastSendRcv void update_advert_entry_data_items(const LLDLEP::DlepMac & rfId, const LLDLEP::DataItems & data_items); - /// Clear the metrics on an entry in the destination advertisement - /// database. - /// @param[in] rfId the RF_ID whose entry will be updated - /// @param[in] data_items the data items associated with rfId - void clear_advert_entry_data_items(const LLDLEP::DlepMac & rfId); - /// Update the state of an entry in the destination advertisement /// database. /// @param[in] rfId the RF_ID whose entry will be updated diff --git a/DestAdvertMessage.h b/DestAdvertMessage.h index b1e5339..44e6f88 100644 --- a/DestAdvertMessage.h +++ b/DestAdvertMessage.h @@ -130,6 +130,8 @@ inline std::pair build_destination_advert( // un-build/de-serialize for reading +// need to transfer DlepPtr parameter for getting the protocfg, +// for construct the dataitem. inline std::pair unbuild_destination_advert( const uint8_t * buff, size_t len, DlepPtr dlep) { diff --git a/DlepServiceImpl.cpp b/DlepServiceImpl.cpp index a956ed5..d7d026f 100644 --- a/DlepServiceImpl.cpp +++ b/DlepServiceImpl.cpp @@ -136,8 +136,8 @@ DlepServiceImpl::destination_update(const DlepMac & mac_address, data_items); if (entry.estate == DestAdvertDBEntry::EntryState::up) { - // entry dataitemsd include not only dataitems that we got as a parametar, - // but somw additional data items. (e.g ip data item). + // entry dataitems include not only dataitems that we got as a parametar, + // but some additional data items. (e.g ip data item). for (const DlepMac & dest : entry.info.destinations) { dlep->local_pdp->updateDestination(dest, entry.data_items, true); @@ -203,8 +203,6 @@ DlepServiceImpl::destination_down(const DlepMac & mac_address) auto result = dlep->dest_advert->find_advert_entry(mac_address); - //dlep->dest_advert->clear_advert_entry_data_items(mac_address); - if (result.first) { dest_down_mac_address = false; diff --git a/Peer.cpp b/Peer.cpp index 24433df..abde7d0 100644 --- a/Peer.cpp +++ b/Peer.cpp @@ -595,7 +595,7 @@ Peer::destination_down(const DlepMac & destination_mac) msg << "to peer=" << peer_id << " destination mac=" << destination_mac; LOG(DLEP_LOG_INFO, msg); - //dlep->dest_advert->clear_advert_entry_data_items(destination_mac); + ProtocolMessage pm {dlep->protocfg, dlep->logger}; pm.add_header(ProtocolStrings::Destination_Down); @@ -1407,23 +1407,12 @@ Peer::handle_destination_up(ProtocolMessage & pm) if (status_message != "") { // following the RFC 8175 protocol (13.8.1), - // MAY issue the appropriate response meesage containing Status Data Item + // MAY issue the appropriate response message containing Status Data Item + ostringstream msg; msg << "peer=" << peer_id << " status=" << ProtocolStrings::Destination_Up_Response << " reason=" << status_message; - LOG(DLEP_LOG_INFO, msg); - - //ProtocolMessage pm {dlep->protocfg, dlep->logger}; - - //pm.add_header(ProtocolStrings::Destination_Up_Response); - //pm.add_status(ProtocolStrings::Inconsistent_Data, status_message); - - // A freshly built message should be parsable. - - //std::string err = pm.parse_and_validate(dlep->is_modem(), __func__); - - //ResponsePendingPtr rp(new ResponsePending(dlep->protocfg, pm)); - //send_message_expecting_response(rp); + LOG(DLEP_LOG_DEBUG, msg); // following the RFC 8175 protocol, // the receiver of inconsistent meesage MUST continue with session processing, @@ -1558,7 +1547,7 @@ Peer::handle_destination_announce(ProtocolMessage & pm) dlep->protocfg->get_message_response_name(pm.get_signal_name()); msg << response_name; - LOG(DLEP_LOG_INFO, msg); + LOG(DLEP_LOG_DEBUG, msg); assert(response_name != ""); @@ -1570,10 +1559,10 @@ Peer::handle_destination_announce(ProtocolMessage & pm) bool already_have_this_dest = peer_pdp->validDestination(destination_mac); msg << response_name << " response name"; - LOG(DLEP_LOG_INFO, msg); + LOG(DLEP_LOG_DEBUG, msg); msg << already_have_this_dest << " already have this dest"; - LOG(DLEP_LOG_INFO, msg); + LOG(DLEP_LOG_DEBUG, msg); std::string statusname; if (! already_have_this_dest) @@ -1608,12 +1597,12 @@ Peer::handle_destination_announce(ProtocolMessage & pm) DestinationDataPtr ddp; msg << "gettting destination data"; - LOG(DLEP_LOG_INFO, msg); + LOG(DLEP_LOG_DEBUG, msg); if (dlep->local_pdp->getDestinationData(destination_mac, &ddp)) { msg << " getting destination data YES"; - LOG(DLEP_LOG_INFO, msg); + LOG(DLEP_LOG_DEBUG, msg); DataItems response_data_items; ddp->get_all_data_items(response_data_items); @@ -1633,7 +1622,7 @@ Peer::handle_destination_announce(ProtocolMessage & pm) statusname = dlep->dlep_client.destination_up(peer_id, destination_mac, data_items); msg << statusname << " status name"; - LOG(DLEP_LOG_INFO, msg); + LOG(DLEP_LOG_DEBUG, msg); // convert empty status name to Success if (statusname == "") @@ -1645,7 +1634,7 @@ Peer::handle_destination_announce(ProtocolMessage & pm) { msg << " What's the right status for a redudant Destination Announce?"; msg << " destination already exists from this peer"; - LOG(DLEP_LOG_INFO, msg); + LOG(DLEP_LOG_DEBUG, msg); // What's the right status for a redundant Destination Announce? statusname = ProtocolStrings::Invalid_Message; @@ -1693,11 +1682,13 @@ Peer::handle_destination_update(ProtocolMessage & pm) if (status_message != "") { // following the RFC 8175 protocol (13.8.1), - // MAY issue the appropriate response meesage containing Status Data Item + // MAY issue the appropriate response message containing Status Data Item + ostringstream msg; msg << "peer=" << peer_id << " status=" << ProtocolStrings::Session_Update_Response << " reason=" << status_message; - LOG(DLEP_LOG_INFO, msg); + LOG(DLEP_LOG_DEBUG, msg); + // following the RFC 8175 protocol, // the receiver of inconsistent meesage MUST continue with session processing, // therefore there is no place for 'return' @@ -2080,7 +2071,7 @@ Peer::set_state_terminating() if (dlep->dest_advert_enabled) { - // clear all destinations associated with this peer + // clear all destinations and ipdataitems associated with this peer dlep->dest_advert->clear_destinations(); dlep->dest_advert->clear_ipdataitems(); }