# SDNPS: A Load-Balanced Topic-Based Publish/Subscribe System in Software-Defined Networking
## 3 Architecture
### Topic Management  
In topic-based publish/subscribe paradigm, topics contact publishers and subscribers. However, topics are not arbitrary strings in actual systems. To prevent from topic bursting, topics must be registered to the server before they are put into use. In SDNPS, topics are structured as a topic tree in which a topic covers all of the topics in its descendant nodes. That is to say, if a subscriber subscribes to a topic, then it also automatically subscribes to those topics on its subtrees. Due to the subscription cover relationship between father topic and child topics in the topic tree, we devise an incremental minimal cost topic-connected overlay algorithm, which significantly reduces the time and space complexity.  
Now that SDN switches can perform filtering operations at low latency [27], we can manipulate flow matching to support this work. The topic tree is an arbitrary multi-bifurcated tree. Transforming the topic tree into a binary tree and then coding this binary tree by the left branch with zero and the right branch with one, we get a binary string named the topic-expression (_tp_) for each topic. Figure 3 exhibits the methods of encoding a topic tree in this paper.  
In particular, all of the events matching the topic tree constitute the event space called \(\Omega\), which is a one-dimensional space. \(\Omega\) can be divided into subspaces according to topics. Any subspace can be identified by a topic-expression. In order to define the subscription cover relation of topics, two functions are defined: \(dlsuffix(tp)\) is used for deleting all of the rear \"1\" of _tp_; \(dlzero(tp)\) deletes the rear \"0\" of _tp_. If \(tp_{i}\) equals \(dlzero(dlsuffix(tp_{j}))\), we say topic \(tp_{i}\) is the father of topic \(tp_{j}\). It is obvious that topic-expression has a partial relation. It fulfills the following characteristics: (1) a subspace \(tp_{i}\) covers the subspace \(tp_{j}\), iff \(tp_{i}\) is a prefix of \(dlzero(dlsuffix(tp_{j}))\), written \(tp_{i}\succ tp_{j}\); (2) if \(tp_{i}\succ tp_{j}\), the subscriber set \(S_{j}\) of \(tp_{j}\) is a subset of the subscriber set \(S_{i}\) of \(tp_{i}\), written \(S_{j}\subseteq S_{i}\).  
For a topic \(tp_{i}\), there are three kinds of events: publish events, subscribe events and unsubscribe events. Subscribe and unsubscribe events should be broadcast to all of the nodes. Therefore, flooding is an appropriate method. Publish events should be routed to those subscribers who have subscribed to them beforehand. SDN-configurable switches must identify these three types of events so that they can perform different processing. For this purpose, we encode event type simultaneously. Two-bit binary coding meets this requirement. This two-bit type code for events is stitched with \(tp_{i}\), forming the identifier (called _typetp_) of a topic \(tp_{i}\). When an event is generated, the _typetp_ is enclosed in its packet header. It is noteworthy that the subspace relationship mentioned above allows the events whose topics have the cover relation to share a common subpath. Recall that the routing of a publish/subscribe system is an obvious multicast problem, so we adopt the IPV6 multicast address to embed _typetp_. Figure 3 describes this process.  
The length of the IPV6 address is 128 bits. According to Figure 3, except for the frontal 25 bits, which are occupied by a fixed section, there are 103 bits for topic codes. Theoretically, the code space is \(2^{103}\). This means that there are at most \(2^{103}\) topics, and it is adequate for our system. In fact, the excessive number of topics, which is associated with the items of flow entries in flow tables, may increase the workload for flow table lookup and degrade the forwarding performance at SDN-configurable switches. Therefore, the flow table entries' aggregation is indispensable to address this problem. This can be easily implemented in light of the hierarchy of the topic tree.