/** * Creates an OpenFlow packet context based on a packet-in. * * @param s OpenFlow switch * @param pkt OpenFlow packet-in * @return the OpenFlow packet context */ public static OpenFlowPacketContext packetContextFromPacketIn(OpenFlowSwitch s, OFPacketIn pkt) { return new DefaultOpenFlowPacketContext(s, pkt); }
@Override public void returnRoleReply(Dpid dpid, RoleState requested, RoleState response) { for (OpenFlowSwitchListener l : ofSwitchListener) { l.receivedRoleReply(dpid, requested, response); } } }
@Override public void processDownstreamMessage(Dpid dpid, List<OFMessage> m) { for (OpenFlowMessageListener listener : ofMessageListener) { listener.handleOutgoingMessage(dpid, m); } }
private void connectInitialDevices() { for (OpenFlowSwitch sw: controller.getSwitches()) { try { listener.switchAdded(new Dpid(sw.getId())); } catch (Exception e) { log.warn("Failed initially adding {} : {}", sw.getStringId(), e.getMessage()); log.debug("Error details:", e); } } }
@Override public boolean isReachable(DeviceId deviceId) { OpenFlowSwitch sw = controller.getSwitch(dpid(deviceId.uri())); return sw != null && sw.isConnected(); }
@Override public void run() { if (sw.getRole() == RoleState.MASTER) { log.trace("MidFlowsTask Collecting AdaptiveStats for {}", sw.getStringId()); // skip collecting because CalAndShortFlowsTask collects entire flow stats from a given switch sw if (callCountMidFlowsTask == ENTIRE_POLL_TIMES) { callCountMidFlowsTask = MID_POLL_TIMES; } else { midFlowsTaskInternal(); callCountMidFlowsTask += MID_POLL_TIMES; } } } }
/** * Produces device URI from the given DPID. * * @param dpid device dpid * @return device URI */ public static URI uri(Dpid dpid) { return uri(dpid.value); }
@Override public void roleChanged(DeviceId deviceId, MastershipRole newRole) { switch (newRole) { case MASTER: controller.setRole(dpid(deviceId.uri()), RoleState.MASTER); break; case STANDBY: controller.setRole(dpid(deviceId.uri()), RoleState.EQUAL); break; case NONE: controller.setRole(dpid(deviceId.uri()), RoleState.SLAVE); break; default: LOG.error("Unknown Mastership state : {}", newRole); } LOG.debug("Accepting mastership role change to {} for device {}", newRole, deviceId); }
@Override public void switchAdded(Dpid dpid) { createCollector(controller.getSwitch(dpid)); }
private void createCollectors() { controller.getSwitches().forEach(this::createCollector); }
@Override public final long getId() { return this.dpid.value(); }
@Override public void processMessage(Dpid dpid, OFMessage m) { processPacket(dpid, m); for (OpenFlowMessageListener listener : ofMessageListener) { listener.handleIncomingMessage(dpid, m); } }
@Override public void run() { for (OpenFlowEventListener listener : ofEventListener) { listener.handleMessage(dpid, msg); } } }
@Override public final String getStringId() { return this.dpid.toString(); }
private void connectInitialDevices() { for (OpenFlowSwitch sw : controller.getSwitches()) { try { listener.switchAdded(new Dpid(sw.getId())); } catch (Exception e) { LOG.warn("Failed initially adding {} : {}", sw.getStringId(), e.getMessage()); LOG.debug("Error details:", e); // disconnect to trigger switch-add later sw.disconnectSwitch(); } PortStatsCollector psc = new PortStatsCollector(sw, portStatsPollFrequency); psc.start(); collectors.put(new Dpid(sw.getId()), psc); } }
@Override public void run() { if (sw.getRole() == RoleState.MASTER) { log.trace("LongFlowsTask Collecting AdaptiveStats for {}", sw.getStringId()); // skip collecting because CalAndShortFlowsTask collects entire flow stats from a given switch sw if (callCountLongFlowsTask == ENTIRE_POLL_TIMES) { callCountLongFlowsTask = LONG_POLL_TIMES; } else { longFlowsTaskInternal(); callCountLongFlowsTask += LONG_POLL_TIMES; } } } }