Software Defined Networking
1752271 Members
4618 Online
108786 Solutions
New Discussion

Re: Noob SDN Programming Questions

 
MatthewHart
Advisor

Noob SDN Programming Questions

Hi Guys,

 

Hopefully someone can help me. I've just started out in the SDN space and I'm trying to get my head around using the API and programming the controller to do my bidding.

 

So what I want to do to start off with is have the ability to detect PACKET_IN and FLOW_REMOVED messages.

From my limited research into the field, I have found a few helpful hints, but Eclipse keeps telling me that various SDK packages cannot be found.

 

Has anyone successfully been able to sniff for these packets and somehow print them somewhere? (preferably in the web UI, but just to a file is ok for now).

 

 

Thanks in advance for any assisstance!

6 REPLIES 6
sdnindia
Trusted Contributor

Re: Noob SDN Programming Questions

Hello MatthewHart,

 

As per SDN programming guide 2.3 [page 212] Posting Alerts-you can make use of  the post function  available under AlertService.You can implement SequencedPacketListener and override the function

public boolean event(MessageContext context){ …}

In this function you can  extract the packet information-

OfmPacketIn packetIn = (OfmPacketIn) context.getPacketIn();

 

//Then packetIn.toString() can  be passed to the post function of AlertService

//post(Severity severity, AlertTopic topic, String origin, String data)  please refer to page 212 of

SDN Programming guide 2.3

 

Please let us know if this helps or still your are facing some problem.

 

 

Thanks,

HP SDN Team

MatthewHart
Advisor

Re: Noob SDN Programming Questions

Thanks for the reply!

 

Once i'm able to resolve the other issue i'm having (http://h30499.www3.hp.com/t5/SDN-Development/How-to-install-SDN/m-p/6618818/highlight/false#M437) I'll jump in and give this a go.

 

I'll reply with results soon (hopefully).

 

 

Thanks for the support thus far!

MatthewHart
Advisor

Re: Noob SDN Programming Questions

Hi Team,

 

When you say to override "public boolean event(MessageContext context){ …}", do you mean "public void event(MessageContext context){ …}"? I can find the latter, but not the former.

 

This is my event listener code and it doesn't generate any alerts in the VAN SDN Software under the Alert Tab.

Do I need to hook this listener into the event handler somehow?

 

 

@Override
public void event(MessageContext context) {
    OfmPacketIn packetIn = (OfmPacketIn) context.getPacketIn();

    alertService.post(Severity.WARNING, alertTopic, "SniffPacketIn: ", packetIn.toString());
}

sdnindia
Trusted Contributor

Re: Noob SDN Programming Questions

Hello Matthew,

Interface SequencedPacketListener has the function  boolean event(MessageContext context)  in SDN JAVA API 2.0 and 2.2.5 versions.
However in version 2.3.5 the function is      void event(MessageContext context)
The referred was for SDN JAVA API 2.0/2.2.5
As pet the SDN Programming guide 2.3 page 213
“When the optional AlertService is set, an alert topic is registered using the AlertService. This registration process will return the alert topic to use when the alert is posted. Alert topics are persistent, thus if the topic was already registered, registering it again will have no effect.
Since AlertService is optional in SwitchManager, the alert will be posted just if the service is available, thus a check for null is needed before posting the alert.”

So please modify code as per page 212
….
if (alertService != null) {
String source = "OpenFlow Switch: " +
id.getValue();
String data = "Switch Retrieved!!”;
alertService.post(Severity.WARNING, alertTopic,
source, data);
}
…..

You can have a look on the example provided in the guide to post alert (for e.g. SwitchManager.java has  data member as alertService of type AlertService  , also you may need to consider other files too ) You may need to look others pages as well e.g. 166 onwards.
You can also try for Auditing with logs from page 215 onwards.

Please let us know if this helps or you still face some issue.

Thanks,
HP SDN Team

MatthewHart
Advisor

Re: Noob SDN Programming Questions

Hi All,

 

I've managed to get the PacketIn processing happening.


I've now turned my attention to the flowremoved events.

I've added my code below to start looking for them at the moment, but Nothing comes up in the alertService.

I've also added the event listeners in the same way as I have with PacketIn.

 

private class FlowListenerImpl implements FlowListener {
/**
* Listener for FlowRemoved Messages
*/
@Override
  public void event(FlowEvent event) {
    OfmFlowRemoved flowRemoved = event.flowRemoved();

    if(flowRemoved != null) {
      long numBytes = flowRemoved.getByteCount();
      String bytes = "" + numBytes;
 
      alertService.post(Severity.WARNING, alertTopic, "Traffic-Monitor(SwitchManager.FlowListenerImpl - toString):", flowRemoved.toString());
      alertService.post(Severity.WARNING, alertTopic, "Traffic-Monitor(SwitchManager.FlowListenerImpl - numBytes):", bytes);
    }
  }
}

sdnindia
Trusted Contributor

Re: Noob SDN Programming Questions

Hello Matthew,

 

Since you are done with PacketIn successfully and having problem with FlowRemoved ,it looks like code inside the if condition-block is not executing.

Please note that OfmFlowRemoved flowRemoved() returns the FlowRemoved message that was received from the datapath. If the event type is not FLOW_REMOVED, this method returns null.

Please make sure the value is not null.

 

Thanks,

HP SDN Team