diff --git a/src/main/java/net/floodlightcontroller/core/web/serializers/StatsReplySerializer.java b/src/main/java/net/floodlightcontroller/core/web/serializers/StatsReplySerializer.java index 2fc9ed9bdff83f0c02b211538e9d8701650f5c9b..16012307a7c0a9763e2c5892cd4933de828cf671 100644 --- a/src/main/java/net/floodlightcontroller/core/web/serializers/StatsReplySerializer.java +++ b/src/main/java/net/floodlightcontroller/core/web/serializers/StatsReplySerializer.java @@ -107,7 +107,7 @@ public class StatsReplySerializer extends JsonSerializer<StatsReply> { switch (reply.getStatType()) { case PORT: // handle port - serializePortReply((List<OFPortStatsReply>) reply.getValues(), jGen); + serializePortReply((List<OFPortStatsReply>) reply.getValues(), jGen); break; case QUEUE: // handle queue @@ -146,7 +146,7 @@ public class StatsReplySerializer extends JsonSerializer<StatsReply> { case METER_FEATURES: break; case PORT_DESC: - serializePortDescReply((List<OFPortDescStatsReply>) reply.getValues(), jGen); + serializePortDescReply((List<OFPortDescStatsReply>) reply.getValues(), jGen); break; default: break; @@ -155,49 +155,53 @@ public class StatsReplySerializer extends JsonSerializer<StatsReply> { } public void serializePortReply(List<OFPortStatsReply> portReplies, JsonGenerator jGen) throws IOException, JsonProcessingException{ - OFPortStatsReply portReply = portReplies.get(0); // we will get only one PortReply and it will contains many OFPortStatsEntry ? + OFPortStatsReply portReply = portReplies.get(0); // we will get only one PortReply and it will contains many OFPortStatsEntry ? jGen.writeStringField("version", portReply.getVersion().toString()); //return the enum name - jGen.writeFieldName("port"); - jGen.writeStartArray(); - for(OFPortStatsEntry entry : portReply.getEntries()) { - jGen.writeStartObject(); - jGen.writeStringField("portNumber",entry.getPortNo().toString()); - jGen.writeNumberField("receivePackets", entry.getRxPackets().getValue()); - jGen.writeNumberField("transmitPackets", entry.getTxPackets().getValue()); - jGen.writeNumberField("receiveBytes", entry.getRxBytes().getValue()); - jGen.writeNumberField("transmitBytes", entry.getTxBytes().getValue()); - jGen.writeNumberField("receiveDropped", entry.getRxDropped().getValue()); - jGen.writeNumberField("transmitDropped", entry.getTxDropped().getValue()); - jGen.writeNumberField("receiveErrors", entry.getRxErrors().getValue()); - jGen.writeNumberField("transmitErrors", entry.getTxErrors().getValue()); - jGen.writeNumberField("receiveFrameErrors", entry.getRxFrameErr().getValue()); - jGen.writeNumberField("receiveOverrunErrors", entry.getRxOverErr().getValue()); - jGen.writeNumberField("receiveCRCErrors", entry.getRxCrcErr().getValue()); - jGen.writeNumberField("collisions", entry.getCollisions().getValue()); - if (OFVersion.OF_13 == entry.getVersion()) { - jGen.writeNumberField("durationSec", entry.getDurationSec()); - jGen.writeNumberField("durationNsec", entry.getDurationNsec()); - } - jGen.writeEndObject(); - } - jGen.writeEndArray(); - } + jGen.writeFieldName("port"); + jGen.writeStartArray(); + for(OFPortStatsEntry entry : portReply.getEntries()) { + jGen.writeStartObject(); + jGen.writeStringField("portNumber",entry.getPortNo().toString()); + jGen.writeNumberField("receivePackets", entry.getRxPackets().getValue()); + jGen.writeNumberField("transmitPackets", entry.getTxPackets().getValue()); + jGen.writeNumberField("receiveBytes", entry.getRxBytes().getValue()); + jGen.writeNumberField("transmitBytes", entry.getTxBytes().getValue()); + jGen.writeNumberField("receiveDropped", entry.getRxDropped().getValue()); + jGen.writeNumberField("transmitDropped", entry.getTxDropped().getValue()); + jGen.writeNumberField("receiveErrors", entry.getRxErrors().getValue()); + jGen.writeNumberField("transmitErrors", entry.getTxErrors().getValue()); + jGen.writeNumberField("receiveFrameErrors", entry.getRxFrameErr().getValue()); + jGen.writeNumberField("receiveOverrunErrors", entry.getRxOverErr().getValue()); + jGen.writeNumberField("receiveCRCErrors", entry.getRxCrcErr().getValue()); + jGen.writeNumberField("collisions", entry.getCollisions().getValue()); + if (OFVersion.OF_13 == entry.getVersion()) { + jGen.writeNumberField("durationSec", entry.getDurationSec()); + jGen.writeNumberField("durationNsec", entry.getDurationNsec()); + } + jGen.writeEndObject(); + } + jGen.writeEndArray(); + } public void serializeFlowReply(List<OFFlowStatsReply> flowReplies, JsonGenerator jGen) throws IOException, JsonProcessingException{ int flowCount = 0; for (OFFlowStatsReply flowReply : flowReplies) { // for each flow stats reply + //Dose the switch will reply multiple OFFlowStatsReply ? + //Or we juse need to use the first item of the list. List<OFFlowStatsEntry> entries = flowReply.getEntries(); + jGen.writeFieldName("flows"); + jGen.writeStartArray(); for (OFFlowStatsEntry entry : entries) { // for each flow + jGen.writeStartObject(); // list flow stats/info - jGen.writeObjectFieldStart("flow" + Integer.toString(flowCount++)); // need to have different object names or JSON parser might only show the last one jGen.writeStringField("version", entry.getVersion().toString()); // return the enum name jGen.writeNumberField("cookie", entry.getCookie().getValue()); - jGen.writeNumberField("table_id", entry.getTableId().getValue()); - jGen.writeNumberField("packet_count", entry.getPacketCount().getValue()); - jGen.writeNumberField("byte_count", entry.getByteCount().getValue()); - jGen.writeNumberField("duration_sec", entry.getDurationSec()); + jGen.writeNumberField("tableId", entry.getTableId().getValue()); + jGen.writeNumberField("packetCount", entry.getPacketCount().getValue()); + jGen.writeNumberField("byteCount", entry.getByteCount().getValue()); + jGen.writeNumberField("durationSeconds", entry.getDurationSec()); jGen.writeNumberField("priority", entry.getPriority()); - jGen.writeNumberField("idle_timeout_sec", entry.getIdleTimeout()); - jGen.writeNumberField("hard_timeout_sec", entry.getHardTimeout()); + jGen.writeNumberField("idleTimeoutSec", entry.getIdleTimeout()); + jGen.writeNumberField("hardTimeoutSec", entry.getHardTimeout()); jGen.writeNumberField("flags", entry.getFlags()); // list flow matches jGen.writeObjectFieldStart("match"); @@ -372,6 +376,7 @@ public class StatsReplySerializer extends JsonSerializer<StatsReply> { } // end not-empty instructions (else) jGen.writeEndObject(); } // end for each OFFlowStatsReply entry + jGen.writeEndArray(); } // end for each OFStatsReply } // end method @@ -577,55 +582,55 @@ public class StatsReplySerializer extends JsonSerializer<StatsReply> { } public void serializePortDescReply(List<OFPortDescStatsReply> portDescReplies, JsonGenerator jGen) throws IOException, JsonProcessingException{ - OFPortDescStatsReply portDescReply = portDescReplies.get(0); // we will get only one PortDescReply and it will contains many OFPortDescStatsEntry ? + OFPortDescStatsReply portDescReply = portDescReplies.get(0); // we will get only one PortDescReply and it will contains many OFPortDescStatsEntry ? jGen.writeStringField("version", portDescReply.getVersion().toString()); //return the enum name - jGen.writeFieldName("portDesc"); - jGen.writeStartArray(); - for(OFPortDesc entry : portDescReply.getEntries()) { - jGen.writeStartObject(); - jGen.writeStringField("portNumber",entry.getPortNo().toString()); - jGen.writeStringField("hardwareAddress", entry.getHwAddr().toString()); - jGen.writeStringField("name", entry.getName()); - switch(entry.getVersion()) { - case OF_10: - jGen.writeNumberField("config", OFPortConfigSerializerVer10.toWireValue(entry.getConfig())); - jGen.writeNumberField("state", OFPortStateSerializerVer10.toWireValue(entry.getState())); - jGen.writeNumberField("currentFeatures", OFPortFeaturesSerializerVer10.toWireValue(entry.getCurr())); - jGen.writeNumberField("advertisedFeatures", OFPortFeaturesSerializerVer10.toWireValue(entry.getAdvertised())); - jGen.writeNumberField("supportedFeatures", OFPortFeaturesSerializerVer10.toWireValue(entry.getSupported())); - jGen.writeNumberField("peerFeatures", OFPortFeaturesSerializerVer10.toWireValue(entry.getPeer())); - break; - case OF_11: - jGen.writeNumberField("config", OFPortConfigSerializerVer11.toWireValue(entry.getConfig())); - jGen.writeNumberField("state", OFPortStateSerializerVer11.toWireValue(entry.getState())); - jGen.writeNumberField("currentFeatures", OFPortFeaturesSerializerVer11.toWireValue(entry.getCurr())); - jGen.writeNumberField("advertisedFeatures", OFPortFeaturesSerializerVer11.toWireValue(entry.getAdvertised())); - jGen.writeNumberField("supportedFeatures", OFPortFeaturesSerializerVer11.toWireValue(entry.getSupported())); - jGen.writeNumberField("peerFeatures", OFPortFeaturesSerializerVer11.toWireValue(entry.getPeer())); - break; - case OF_12: - jGen.writeNumberField("config", OFPortConfigSerializerVer12.toWireValue(entry.getConfig())); - jGen.writeNumberField("state", OFPortStateSerializerVer12.toWireValue(entry.getState())); - jGen.writeNumberField("currentFeatures", OFPortFeaturesSerializerVer12.toWireValue(entry.getCurr())); - jGen.writeNumberField("advertisedFeatures", OFPortFeaturesSerializerVer12.toWireValue(entry.getAdvertised())); - jGen.writeNumberField("supportedFeatures", OFPortFeaturesSerializerVer12.toWireValue(entry.getSupported())); - jGen.writeNumberField("peerFeatures", OFPortFeaturesSerializerVer12.toWireValue(entry.getPeer())); - break; - case OF_13: - jGen.writeNumberField("config", OFPortConfigSerializerVer13.toWireValue(entry.getConfig())); - jGen.writeNumberField("state", OFPortStateSerializerVer13.toWireValue(entry.getState())); - jGen.writeNumberField("currentFeatures", OFPortFeaturesSerializerVer13.toWireValue(entry.getCurr())); - jGen.writeNumberField("advertisedFeatures", OFPortFeaturesSerializerVer13.toWireValue(entry.getAdvertised())); - jGen.writeNumberField("supportedFeatures", OFPortFeaturesSerializerVer13.toWireValue(entry.getSupported())); - jGen.writeNumberField("peerFeatures", OFPortFeaturesSerializerVer13.toWireValue(entry.getPeer())); - break; - } - if (OFVersion.OF_10 != entry.getVersion()) { - jGen.writeNumberField("currSpeed",entry.getCurrSpeed()); - jGen.writeNumberField("maxSpeed",entry.getMaxSpeed()); - } - jGen.writeEndObject(); - } - jGen.writeEndArray(); - } + jGen.writeFieldName("portDesc"); + jGen.writeStartArray(); + for(OFPortDesc entry : portDescReply.getEntries()) { + jGen.writeStartObject(); + jGen.writeStringField("portNumber",entry.getPortNo().toString()); + jGen.writeStringField("hardwareAddress", entry.getHwAddr().toString()); + jGen.writeStringField("name", entry.getName()); + switch(entry.getVersion()) { + case OF_10: + jGen.writeNumberField("config", OFPortConfigSerializerVer10.toWireValue(entry.getConfig())); + jGen.writeNumberField("state", OFPortStateSerializerVer10.toWireValue(entry.getState())); + jGen.writeNumberField("currentFeatures", OFPortFeaturesSerializerVer10.toWireValue(entry.getCurr())); + jGen.writeNumberField("advertisedFeatures", OFPortFeaturesSerializerVer10.toWireValue(entry.getAdvertised())); + jGen.writeNumberField("supportedFeatures", OFPortFeaturesSerializerVer10.toWireValue(entry.getSupported())); + jGen.writeNumberField("peerFeatures", OFPortFeaturesSerializerVer10.toWireValue(entry.getPeer())); + break; + case OF_11: + jGen.writeNumberField("config", OFPortConfigSerializerVer11.toWireValue(entry.getConfig())); + jGen.writeNumberField("state", OFPortStateSerializerVer11.toWireValue(entry.getState())); + jGen.writeNumberField("currentFeatures", OFPortFeaturesSerializerVer11.toWireValue(entry.getCurr())); + jGen.writeNumberField("advertisedFeatures", OFPortFeaturesSerializerVer11.toWireValue(entry.getAdvertised())); + jGen.writeNumberField("supportedFeatures", OFPortFeaturesSerializerVer11.toWireValue(entry.getSupported())); + jGen.writeNumberField("peerFeatures", OFPortFeaturesSerializerVer11.toWireValue(entry.getPeer())); + break; + case OF_12: + jGen.writeNumberField("config", OFPortConfigSerializerVer12.toWireValue(entry.getConfig())); + jGen.writeNumberField("state", OFPortStateSerializerVer12.toWireValue(entry.getState())); + jGen.writeNumberField("currentFeatures", OFPortFeaturesSerializerVer12.toWireValue(entry.getCurr())); + jGen.writeNumberField("advertisedFeatures", OFPortFeaturesSerializerVer12.toWireValue(entry.getAdvertised())); + jGen.writeNumberField("supportedFeatures", OFPortFeaturesSerializerVer12.toWireValue(entry.getSupported())); + jGen.writeNumberField("peerFeatures", OFPortFeaturesSerializerVer12.toWireValue(entry.getPeer())); + break; + case OF_13: + jGen.writeNumberField("config", OFPortConfigSerializerVer13.toWireValue(entry.getConfig())); + jGen.writeNumberField("state", OFPortStateSerializerVer13.toWireValue(entry.getState())); + jGen.writeNumberField("currentFeatures", OFPortFeaturesSerializerVer13.toWireValue(entry.getCurr())); + jGen.writeNumberField("advertisedFeatures", OFPortFeaturesSerializerVer13.toWireValue(entry.getAdvertised())); + jGen.writeNumberField("supportedFeatures", OFPortFeaturesSerializerVer13.toWireValue(entry.getSupported())); + jGen.writeNumberField("peerFeatures", OFPortFeaturesSerializerVer13.toWireValue(entry.getPeer())); + break; + } + if (OFVersion.OF_10 != entry.getVersion()) { + jGen.writeNumberField("currSpeed",entry.getCurrSpeed()); + jGen.writeNumberField("maxSpeed",entry.getMaxSpeed()); + } + jGen.writeEndObject(); + } + jGen.writeEndArray(); + } } diff --git a/src/main/resources/web/js/models/switchmodel.js b/src/main/resources/web/js/models/switchmodel.js index f7f93bca9e87fcdfff40f9a64e9dab65d71fca15..785e1f6464beac7e54ad13cba154ec656eb664d6 100644 --- a/src/main/resources/web/js/models/switchmodel.js +++ b/src/main/resources/web/js/models/switchmodel.js @@ -73,7 +73,6 @@ window.Switch = Backbone.Model.extend({ dataType:"json", success:function (data) { //console.log("fetched switch " + self.id + " ports"); - console.log(data['port']); var old_ids = self.ports.pluck('id'); //console.log("old_ids" + old_ids); @@ -103,7 +102,6 @@ window.Switch = Backbone.Model.extend({ console.log("removing port " + p); self.remove({id:p}); }); - console.log(self.ports); } }), $.ajax({ @@ -111,7 +109,7 @@ window.Switch = Backbone.Model.extend({ dataType:"json", success:function (data) { //console.log("fetched switch " + self.id + " features"); - console.log(data['portDesc']); + //console.log(data['portDesc']); // update port models _.each(data['portDesc'], function(p) { p.id = self.id+'-'+p.portNumber; @@ -168,7 +166,7 @@ window.Switch = Backbone.Model.extend({ dataType:"json", success:function (data) { //console.log("fetched switch " + self.id + " flows"); - var flows = data[self.id]; + var flows = data['flows']; //console.log(flows); // create flow models @@ -178,81 +176,31 @@ window.Switch = Backbone.Model.extend({ // build human-readable match f.matchHTML = ''; - if(!(f.match.wildcards & (1<<0))) { // input port - f.matchHTML += "port=" + f.match.inputPort + ", "; + if(f.hasOwnProperty('match')) { + _.each(f.match, function(value , key) { + f.matchHTML += key + "=" + value +" "; + },f); } - if(!(f.match.wildcards & (1<<1))) { // VLAN ID - f.matchHTML += "VLAN=" + f.match.dataLayerVirtualLan + ", "; - } - if(!(f.match.wildcards & (1<<20))) { // VLAN prio - f.matchHTML += "prio=" + f.match.dataLayerVirtualLanPriorityCodePoint + ", "; - } - if(!(f.match.wildcards & (1<<2))) { // src MAC - f.matchHTML += "src=<a href='/host/" + f.match.dataLayerSource + "'>" + - f.match.dataLayerSource + "</a>, "; - } - if(!(f.match.wildcards & (1<<3))) { // dest MAC - f.matchHTML += "dest=<a href='/host/" + f.match.dataLayerDestination + "'>" + - f.match.dataLayerDestination + "</a>, "; - } - if(!(f.match.wildcards & (1<<4))) { // Ethertype - // TODO print a human-readable name instead of hex - f.matchHTML += "ethertype=" + f.match.dataLayerType + ", "; - } - if(!(f.match.wildcards & (1<<5))) { // IP protocol - // TODO print a human-readable name - f.matchHTML += "proto=" + f.match.networkProtocol + ", "; - } - if(!(f.match.wildcards & (1<<6))) { // TCP/UDP source port - f.matchHTML += "IP src port=" + f.match.transportSource + ", "; - } - if(!(f.match.wildcards & (1<<7))) { // TCP/UDP dest port - f.matchHTML += "IP dest port=" + f.match.transportDestination + ", "; - } - if(!(f.match.wildcards & (32<<8))) { // src IP - f.matchHTML += "src=" + f.match.networkSource + ", "; - } - if(!(f.match.wildcards & (32<<14))) { // dest IP - f.matchHTML += "dest=" + f.match.networkDestination + ", "; - } - if(!(f.match.wildcards & (1<<21))) { // IP TOS - f.matchHTML += "TOS=" + f.match.networkTypeOfService + ", "; - } - // remove trailing ", " f.matchHTML = f.matchHTML.substr(0, f.matchHTML.length - 2); - - // build human-readable action list - f.actionText = _.reduce(f.actions, function (memo, a) { - switch (a.type) { - case "OUTPUT": - return memo + "output " + a.port + ', '; - case "OPAQUE_ENQUEUE": - return memo + "enqueue " + a.port + ':' + a.queueId + ', '; - case "STRIP_VLAN": - return memo + "strip VLAN, "; - case "SET_VLAN_ID": - return memo + "VLAN=" + a.virtualLanIdentifier + ', '; - case "SET_VLAN_PCP": - return memo + "prio=" + a.virtualLanPriorityCodePoint + ', '; - case "SET_DL_SRC": - return memo + "src=" + a.dataLayerAddress + ', '; - case "SET_DL_DST": - return memo + "dest=" + a.dataLayerAddress + ', '; - case "SET_NW_TOS": - return memo + "TOS=" + a.networkTypeOfService + ', '; - case "SET_NW_SRC": - return memo + "src=" + a.networkAddress + ', '; - case "SET_NW_DST": - return memo + "dest=" + a.networkAddress + ', '; - case "SET_TP_SRC": - return memo + "src port=" + a.transportPort + ', '; - case "SET_TP_DST": - return memo + "dest port=" + a.transportPort + ', '; + + f.applyActionText = ''; + f.writeActionText = ''; + if(f.hasOwnProperty('instructions')) { + if(f.instructions.hasOwnProperty('apply_actions')) { + _.each(f.instructions.apply_actions, function(value, key) { + f.applyActionText += key + ":" + value +" "; + },f); + } + if(f.instructions.hasOwnProperty('write_actions')) { + _.each(f.instructions.write_actions, function(value, key) { + f.writeActionText += key + ":" + value +" "; + },f); } - }, ""); - // remove trailing ", " - f.actionText = f.actionText.substr(0, f.actionText.length - 2); + } + // build human-readable action list + f.applyActionText = f.applyActionText.substr(0, f.applyActionText.length - 2); + f.writeActionText = f.writeActionText.substr(0, f.writeActionText.length - 2); //console.log(f); self.flows.add(f, {silent: true}); }); diff --git a/src/main/resources/web/tpl/flow-list-item.html b/src/main/resources/web/tpl/flow-list-item.html index 7c099c3e7e0e43c9612412dc7b4220fcbe7b1001..4fb9a3ec87f5058627483d6114807ea7ab5978db 100644 --- a/src/main/resources/web/tpl/flow-list-item.html +++ b/src/main/resources/web/tpl/flow-list-item.html @@ -1 +1 @@ - <td><%= cookie %></td><td><%= priority %></td><td><%= matchHTML %></td><td><%= actionText %></td><td><%= packetCount %></td><td><%= byteCount %></td><td><%= durationSeconds %> s</td><td><%= idleTimeout %> s</td> + <td><%= cookie %></td><td><%= priority %></td><td><%= matchHTML %></td><td><%= applyActionText %></td><td><%= writeActionText %></td><td><%= packetCount %></td><td><%= byteCount %></td><td><%= durationSeconds %> s</td><td><%= idleTimeoutSec %> s</td> diff --git a/src/main/resources/web/tpl/flow-list.html b/src/main/resources/web/tpl/flow-list.html index 21a30cf8d1b67633cb5869e68e88c51f96db82ec..3c23a292e47c7565566a0dc70ca783e5af91c046 100644 --- a/src/main/resources/web/tpl/flow-list.html +++ b/src/main/resources/web/tpl/flow-list.html @@ -2,7 +2,7 @@ <h1>Flows (<%= nflows %>)</h1> </div> <table class="table table-striped flow-table"> - <thead><tr><th>Cookie</th><th>Priority</th><th>Match</th><th>Action</th><th>Packets</th><th>Bytes</th><th>Age</th><th>Timeout</th></tr></thead> + <thead><tr><th>Cookie</th><th>Priority</th><th>Match</th><th>Apply Actions</th><th>Write Actions</th><th>Packets</th><th>Bytes</th><th>Age</th><th>Timeout</th></tr></thead> <tbody> <!-- flows will be inserted here by FlowListView:render --> </tbody> @@ -16,4 +16,4 @@ <li><a href="">→</a> </ul></div> --> - \ No newline at end of file +