This cleans up the CFM library a bit by pushing ccm composition
details into the packets library.
---
lib/cfm.c | 13 ++++---------
lib/packets.c | 17 +++++++++++++++++
lib/packets.h | 4 ++++
3 files changed, 25 insertions(+), 9 deletions(-)
diff --git a/lib/cfm.c b/lib/cfm.c
index d9c8fb5..d618dc5 100644
--- a/lib/cfm.c
+++ b/lib/cfm.c
@@ -109,20 +109,15 @@ lookup_remote_mp(const struct hmap *hmap, uint16_t mpid)
}
static struct ofpbuf *
-compose_ccm(struct cfm_internal *cfmi)
+compose_message(struct cfm_internal *cfmi)
{
struct ccm ccm;
struct ofpbuf *packet;
packet = ofpbuf_new(0);
- ccm.mdlevel_version = 0;
- ccm.opcode = 1;
- ccm.tlv_offset = 70;
- ccm.seq = htonl(++cfmi->seq);
- ccm.mpid = htons(cfmi->cfm.mpid);
- ccm.flags = cfmi->ccm_interval;
- memcpy(ccm.maid, cfmi->cfm.maid, sizeof ccm.maid);
+ compose_ccm(cfmi->cfm.mpid, cfmi->cfm.maid, cfmi->ccm_interval,
+ ++cfmi->seq, &ccm);
compose_packet(packet, eth_addr_ccm, cfmi->cfm.eth_src, ETH_TYPE_CFM,
&ccm, sizeof ccm);
@@ -232,7 +227,7 @@ cfm_run(struct cfm *cfm)
if (now >= cfmi->ccm_sent + cfmi->ccm_interval_ms) {
cfmi->ccm_sent = now;
- return compose_ccm(cfmi);
+ return compose_message(cfmi);
}
return NULL;
diff --git a/lib/packets.c b/lib/packets.c
index b5ec440..8c8f79c 100644
--- a/lib/packets.c
+++ b/lib/packets.c
@@ -224,6 +224,23 @@ compose_packet(struct ofpbuf *b, const uint8_t
eth_dst[ETH_ADDR_LEN],
eth->eth_type = htons(eth_type);
}
+/* Populates 'ccm' with an 802.1ag CCM message comprised of the given
+ * parameters. */
+void
+compose_ccm(uint16_t mpid, uint8_t maid[CCM_MAID_LEN],
+ uint8_t interval, uint32_t seq, struct ccm *ccm)
+{
+
+ ccm->mdlevel_version = 0;
+ ccm->opcode = 1;
+ ccm->flags = interval;
+ ccm->tlv_offset = 70;
+ ccm->seq = htonl(seq);
+ ccm->mpid = htons(mpid);
+ memcpy(ccm->maid, maid, CCM_MAID_LEN);
+ memset(ccm->zero, 0, 16);
+}
+
/* Populates 'pdu' with a LACP PDU comprised of 'actor' and 'partner'. */
void
compose_lacp_pdu(const struct lacp_info *actor,
diff --git a/lib/packets.h b/lib/packets.h
index 511ad02..3134fb8 100644
--- a/lib/packets.h
+++ b/lib/packets.h
@@ -420,6 +420,10 @@ compose_packet(struct ofpbuf *, const uint8_t
eth_dst[ETH_ADDR_LEN],
const uint8_t eth_src[ETH_ADDR_LEN], uint16_t eth_type,
const void *data, size_t data_len);
+void
+compose_ccm(uint16_t mpid, uint8_t maid[CCM_MAID_LEN],
+ uint8_t interval, uint32_t seq, struct ccm *);
+
/* Masks for lacp_info state member. */
#define LACP_STATE_ACT 0x01 /* Activity. Active or passive? */
#define LACP_STATE_TIME 0x02 /* Timeout. Short or long timeout? */
--
1.7.4.1
_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev