1 === Wiring up notifications
5 We need to translate OpenFlow messages coming up from the
6 <<_openflow_protocol_library_developer_guide,OpenFlow Protocol Library>>
7 into MD-SAL Notification objects and then publish them to the
13 . Create a Translator class
14 . Register the Translator
15 . Register the notificationPopListener to handle your Notification
18 [[create-a-translator-class]]
19 ===== Create a Translator class
21 You can see an example in
22 https://git.opendaylight.org/gerrit/gitweb?p=openflowplugin.git;a=blob;f=openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/translator/PacketInTranslator.java;hb=refs/heads/stable/boron[PacketInTranslator.java].
24 First, simply create the class
26 ---------------------------------------------------------------------------------------------
27 public class PacketInTranslator implements IMDMessageTranslator<OfHeader, List<DataObject>> {
28 ---------------------------------------------------------------------------------------------
30 Then implement the translate function:
32 ---------------------------------------------------------------------------------------------
33 public class PacketInTranslator implements IMDMessageTranslator<OfHeader, List<DataObject>> {
35 protected static final Logger LOG = LoggerFactory
36 .getLogger(PacketInTranslator.class);
38 public PacketReceived translate(SwitchConnectionDistinguisher cookie,
39 SessionContext sc, OfHeader msg) {
42 ---------------------------------------------------------------------------------------------
44 Make sure to check that you are dealing with the expected type and cast
47 ---------------------------------------------------------------------------
48 if(msg instanceof PacketInMessage) {
49 PacketInMessage message = (PacketInMessage)msg;
50 List<DataObject> list = new CopyOnWriteArrayList<DataObject>();
51 ---------------------------------------------------------------------------
53 Do your transation work and return
55 -------------------------------------------------------------
56 PacketReceived pktInEvent = pktInBuilder.build();
59 -------------------------------------------------------------
61 [[register-your-translator-class]]
62 ===== Register your Translator Class
64 Next you need to go to
65 https://git.opendaylight.org/gerrit/gitweb?p=openflowplugin.git;a=blob;f=openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/MDController.java;hb=refs/heads/stable/boron[MDController.java]
66 and in init() add register your Translator:
68 -----------------------------------------------------------------------------------
70 LOG.debug("Initializing!");
71 messageTranslators = new ConcurrentHashMap<>();
72 popListeners = new ConcurrentHashMap<>();
73 //TODO: move registration to factory
74 addMessageTranslator(ErrorMessage.class, OF10, new ErrorTranslator());
75 addMessageTranslator(ErrorMessage.class, OF13, new ErrorTranslator());
76 addMessageTranslator(PacketInMessage.class,OF10, new PacketInTranslator());
77 addMessageTranslator(PacketInMessage.class,OF13, new PacketInTranslator());
78 -----------------------------------------------------------------------------------
80 Notice that there is a separate registration for each of OpenFlow 1.0 and OpenFlow 1.3.
81 Basically, you indicate the type of OpenFlow Protocol Library message you wish to
82 translate for, the OpenFlow version, and an instance of your Translator.
84 [[register-your-md-sal-message-for-notification-to-the-md-sal]]
85 ===== Register your MD-SAL Message for Notification to the MD-SAL
87 Now, also in MDController.init() register to have the
88 notificationPopListener handle your MD-SAL Message:
90 ---------------------------------------------------------------------------------------
91 addMessagePopListener(PacketReceived.class, new NotificationPopListener<DataObject>());
92 ---------------------------------------------------------------------------------------
97 That's all there is to it. Now when a message comes up from the
98 OpenFlow Protocol Library, it will be translated and published to the MD-SAL.