@Test public void testAddSwitchValues() throws Exception { List<Values> values = speakerBolt.addSwitch(switchMessage); assertEquals(3, values.size()); int count = 0; for (Values value : values) { InfoMessage infoMessage = mapper.readValue((String) value.get(1), InfoMessage.class); if (count < 2) { assertThat(infoMessage.getData(), instanceOf(SwitchInfoData.class)); SwitchInfoData sw = (SwitchInfoData) infoMessage.getData(); assertEquals(dpid, sw.getSwitchId()); } else { assertThat(infoMessage.getData(), instanceOf(PortInfoData.class)); PortInfoData port = (PortInfoData) infoMessage.getData(); assertEquals(dpid, port.getSwitchId()); if (port.getPortNo() == localLinkPort) { assertEquals(PortChangeType.UP, port.getState()); } else { assertEquals(PortChangeType.DOWN, port.getState()); } } count++; } }
protected List<Values> addSwitch(AddSwitchCommand data) throws Exception { List<Values> values = new ArrayList<>(); SwitchId dpid = data.getDpid(); if (switches.get(dpid) == null) { ISwitchImpl sw = new ISwitchImpl(dpid, data.getNumOfPorts(), PortStateType.DOWN); switches.put(new SwitchId(sw.getDpid().toString()), sw); values.add(new Values("INFO", makeSwitchMessage(sw, SwitchChangeType.ADDED))); values.add(new Values("INFO", makeSwitchMessage(sw, SwitchChangeType.ACTIVATED))); } return values; }
SpeakerBolt extends BaseRichBolt { protected List<Values> addSwitch(AddSwitchCommand data) throws Exception { List<Values> values = new ArrayList<>(); SwitchId dpid = data.getDpid(); if (switches.get(dpid) == null) { ISwitchImpl sw = new ISwitchImpl(dpid, data.getNumOfPorts(), PortStateType.DOWN); switches.put(new SwitchId(sw.getDpid().toString()), sw); values.add(new Values("INFO", makeSwitchMessage(sw, SwitchChangeType.ADDED))); values.add(new Values("INFO", makeSwitchMessage(sw, SwitchChangeType.ACTIVATED))); } return values; } }
SpeakerBolt extends BaseRichBolt { protected List<Values> addSwitch(AddSwitchCommand data) throws Exception { List<Values> values = new ArrayList<>(); SwitchId dpid = data.getDpid(); if (switches.get(dpid) == null) { ISwitchImpl sw = new ISwitchImpl(dpid, data.getNumOfPorts(), PortStateType.DOWN); switches.put(new SwitchId(sw.getDpid().toString()), sw); values.add(new Values("INFO", makeSwitchMessage(sw, SwitchChangeType.ADDED))); values.add(new Values("INFO", makeSwitchMessage(sw, SwitchChangeType.ACTIVATED))); } return values; }  }
SpeakerBolt extends BaseRichBolt { protected List<Values> addSwitch(AddSwitchCommand data) throws Exception { List<Values> values = new ArrayList<>(); SwitchId dpid = data.getDpid(); if (switches.get(dpid) == null) { ISwitchImpl sw = new ISwitchImpl(dpid, data.getNumOfPorts(), PortStateType.DOWN); switches.put(new SwitchId(sw.getDpid().toString()), sw); values.add(new Values("INFO", makeSwitchMessage(sw, SwitchChangeType.ADDED))); values.add(new Values("INFO", makeSwitchMessage(sw, SwitchChangeType.ACTIVATED))); } return values; }  ISwitchImpl getSwitch(SwitchId name); void doSimulatorCommand(Tuple tuple); void doCommand(Tuple tuple); @Override void prepare(Map map, TopologyContext topologyContext, OutputCollector outputCollector); @Override void execute(Tuple tuple); @Override void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer); }
SpeakerBolt extends BaseRichBolt { protected List<Values> addSwitch(AddSwitchCommand data) throws Exception { List<Values> values = new ArrayList<>(); SwitchId dpid = data.getDpid(); if (switches.get(dpid) == null) { ISwitchImpl sw = new ISwitchImpl(dpid, data.getNumOfPorts(), PortStateType.DOWN); switches.put(new SwitchId(sw.getDpid().toString()), sw); values.add(new Values("INFO", makeSwitchMessage(sw, SwitchChangeType.ADDED))); values.add(new Values("INFO", makeSwitchMessage(sw, SwitchChangeType.ACTIVATED))); } return values; }  ISwitchImpl getSwitch(SwitchId name); void doSimulatorCommand(Tuple tuple); void doCommand(Tuple tuple); @Override void prepare(Map map, TopologyContext topologyContext, OutputCollector outputCollector); @Override void execute(Tuple tuple); @Override void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer);  }