Simon Hunt | e6f6461 | 2017-04-28 00:01:48 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | * |
| 16 | */ |
| 17 | |
| 18 | package org.onosproject.ui.impl.topo; |
| 19 | |
| 20 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 21 | import com.google.common.collect.ImmutableSet; |
| 22 | import org.onlab.osgi.ServiceDirectory; |
| 23 | import org.onosproject.ui.RequestHandler; |
| 24 | import org.onosproject.ui.UiConnection; |
| 25 | import org.onosproject.ui.UiMessageHandler; |
| 26 | import org.slf4j.Logger; |
| 27 | import org.slf4j.LoggerFactory; |
| 28 | |
| 29 | import java.util.Collection; |
| 30 | |
| 31 | /** |
| 32 | * Server-side component to handle messages pertaining to topo-2 traffic. |
| 33 | */ |
| 34 | public class Topo2TrafficMessageHandler extends UiMessageHandler { |
| 35 | |
| 36 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 37 | |
| 38 | // === Inbound event identifiers |
| 39 | private static final String REQUEST_ALL_TRAFFIC = "topo2RequestAllTraffic"; |
| 40 | private static final String CANCEL_TRAFFIC = "topo2CancelTraffic"; |
| 41 | |
| 42 | // === Outbound event identifiers |
| 43 | private static final String HIGHLIGHTS = "topo2Highlights"; |
| 44 | |
| 45 | // private UiTopoSession topoSession; |
| 46 | // private Topo2Jsonifier t2json; |
| 47 | |
| 48 | @Override |
| 49 | public void init(UiConnection connection, ServiceDirectory directory) { |
| 50 | super.init(connection, directory); |
| 51 | |
| 52 | // get the topo session from the UiWebSocket |
| 53 | // topoSession = ((UiWebSocket) connection).topoSession(); |
| 54 | // t2json = new Topo2Jsonifier(directory, connection.userName()); |
| 55 | |
| 56 | } |
| 57 | |
| 58 | @Override |
| 59 | protected Collection<RequestHandler> createRequestHandlers() { |
| 60 | return ImmutableSet.of( |
| 61 | new Topo2AllTraffic(), |
| 62 | new Topo2CancelTraffic() |
| 63 | ); |
| 64 | } |
| 65 | |
| 66 | // ================================================================== |
| 67 | |
| 68 | private final class Topo2AllTraffic extends RequestHandler { |
| 69 | private Topo2AllTraffic() { |
| 70 | super(REQUEST_ALL_TRAFFIC); |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public void process(ObjectNode payload) { |
| 75 | String mode = string(payload, "trafficType"); |
| 76 | log.debug("SHOW TRAFFIC: " + mode); |
| 77 | switch (mode) { |
| 78 | case "flowStatsBytes": |
| 79 | // TODO: invoke traffic monitor for flow stats / bytes |
| 80 | break; |
| 81 | |
| 82 | case "portStatsBitSec": |
| 83 | // TODO: invoke traffic monitor for port stats / bps |
| 84 | break; |
| 85 | |
| 86 | case "portStatsPktSec": |
| 87 | // TODO: invoke traffic monitor for port stats / pps |
| 88 | break; |
| 89 | |
| 90 | default: |
| 91 | log.warn("Unknown traffic monitor type: " + mode); |
| 92 | break; |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | private final class Topo2CancelTraffic extends RequestHandler { |
| 98 | private Topo2CancelTraffic() { |
| 99 | super(CANCEL_TRAFFIC); |
| 100 | } |
| 101 | |
| 102 | @Override |
| 103 | public void process(ObjectNode payload) { |
| 104 | log.debug("CANCEL TRAFFIC"); |
| 105 | // TODO: tell traffic monitor to quit monitoring traffic |
| 106 | } |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | |