use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.
the class FujitsuVoltAlertConfig method subscribe.
@Override
public boolean subscribe(String mode) {
DriverHandler handler = handler();
NetconfController controller = handler.get(NetconfController.class);
MastershipService mastershipService = handler.get(MastershipService.class);
DeviceId ncDeviceId = handler.data().deviceId();
checkNotNull(controller, "Netconf controller is null");
if (!mastershipService.isLocalMaster(ncDeviceId)) {
log.warn("Not master for {} Use {} to execute command", ncDeviceId, mastershipService.getMasterFor(ncDeviceId));
return false;
}
if (mode != null) {
if (!DISABLE.equals(mode)) {
log.error("Invalid mode: {}", mode);
return false;
}
}
try {
if (mode != null) {
controller.getDevicesMap().get(ncDeviceId).getSession().endSubscription();
} else {
StringBuilder request = new StringBuilder();
request.append(ANGLE_LEFT + NOTIFY_ALERT + SPACE);
request.append(VOLT_NE_NAMESPACE + SLASH + ANGLE_RIGHT);
controller.getDevicesMap().get(ncDeviceId).getSession().startSubscription(request.toString());
}
} catch (NetconfException e) {
log.error("Cannot communicate to device {} exception {}", ncDeviceId, e);
return false;
}
return true;
}
use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.
the class FujitsuVoltAlertConfig method getAlertFilter.
@Override
public String getAlertFilter() {
DriverHandler handler = handler();
NetconfController controller = handler.get(NetconfController.class);
MastershipService mastershipService = handler.get(MastershipService.class);
DeviceId ncDeviceId = handler.data().deviceId();
checkNotNull(controller, "Netconf controller is null");
String reply = null;
if (!mastershipService.isLocalMaster(ncDeviceId)) {
log.warn("Not master for {} Use {} to execute command", ncDeviceId, mastershipService.getMasterFor(ncDeviceId));
return null;
}
try {
StringBuilder request = new StringBuilder();
request.append(VOLT_NE_OPEN + VOLT_NE_NAMESPACE);
request.append(ANGLE_RIGHT + NEW_LINE);
request.append(buildStartTag(VOLT_ALERTS)).append(buildEmptyTag(ALERT_FILTER)).append(buildEndTag(VOLT_ALERTS)).append(VOLT_NE_CLOSE);
reply = controller.getDevicesMap().get(ncDeviceId).getSession().get(request.toString(), REPORT_ALL);
} catch (NetconfException e) {
log.error("Cannot communicate to device {} exception {}", ncDeviceId, e);
}
return reply;
}
use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.
the class FujitsuVoltControllerConfig method getControllers.
@Override
public List<ControllerInfo> getControllers() {
DriverHandler handler = handler();
NetconfController controller = handler.get(NetconfController.class);
MastershipService mastershipService = handler.get(MastershipService.class);
DeviceId ncDeviceId = handler.data().deviceId();
checkNotNull(controller, "Netconf controller is null");
List<ControllerInfo> controllers = new ArrayList<>();
if (mastershipService.isLocalMaster(ncDeviceId)) {
try {
StringBuilder request = new StringBuilder();
request.append(VOLT_NE_OPEN + VOLT_NE_NAMESPACE + ">\n");
request.append(buildEmptyTag(VOLT_OFCONFIG));
request.append(VOLT_NE_CLOSE);
String reply;
reply = controller.getDevicesMap().get(ncDeviceId).getSession().get(request.toString(), REPORT_ALL);
log.debug("Reply XML {}", reply);
controllers.addAll(parseStreamVoltControllers(XmlConfigParser.loadXml(new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8)))));
} catch (NetconfException e) {
log.error("Cannot communicate to device {} ", ncDeviceId);
}
} else {
log.warn("I'm not master for {} please use master, {} to execute command", ncDeviceId, mastershipService.getMasterFor(ncDeviceId));
}
return ImmutableList.copyOf(controllers);
}
use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.
the class FujitsuVoltControllerConfig method setControllers.
@Override
public void setControllers(List<ControllerInfo> controllers) {
DriverHandler handler = handler();
NetconfController controller = handler.get(NetconfController.class);
MastershipService mastershipService = handler.get(MastershipService.class);
DeviceId ncdeviceId = handler.data().deviceId();
checkNotNull(controller, "Netconf controller is null");
if (mastershipService.isLocalMaster(ncdeviceId)) {
try {
NetconfDevice device = controller.getNetconfDevice(ncdeviceId);
String config = createVoltControllersConfig(XmlConfigParser.loadXml(getClass().getResourceAsStream(RESOURCE_XML)), RUNNING, MERGE, controllers);
device.getSession().editConfig(config.substring(config.indexOf(END_LICENSE_HEADER) + END_LICENSE_HEADER.length()));
} catch (NetconfException e) {
log.error("Cannot communicate to device {} , exception {}", ncdeviceId, e);
}
} else {
log.warn("I'm not master for {} please use master, {} to execute command", ncdeviceId, mastershipService.getMasterFor(ncdeviceId));
}
}
use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.
the class FujitsuVoltFwdlConfig method upgradeFirmwareOndemand.
@Override
public String upgradeFirmwareOndemand(String target) {
DriverHandler handler = handler();
NetconfController controller = handler.get(NetconfController.class);
MastershipService mastershipService = handler.get(MastershipService.class);
DeviceId ncDeviceId = handler.data().deviceId();
checkNotNull(controller, "Netconf controller is null");
String reply = null;
int count;
if (!mastershipService.isLocalMaster(ncDeviceId)) {
log.warn("Not master for {} Use {} to execute command", ncDeviceId, mastershipService.getMasterFor(ncDeviceId));
return null;
}
String[] data = target.split(COLON);
if ((data.length < TWO) || (data.length > THREE)) {
log.error("Invalid number of arguments");
return null;
}
String[] onuList = data[SECOND_PART].split(COMMA);
if (onuList.length == ZERO) {
log.error("No ONU listed");
return null;
}
if ((data.length > TWO) && (!AUTO.equals(data[THIRD_PART]))) {
log.error("Invalid reboot-mode {}", data[THIRD_PART]);
return null;
}
try {
StringBuilder request = new StringBuilder();
request.append(ANGLE_LEFT + ONDEMAND_FIRMWARE_UPGRADE + SPACE);
request.append(VOLT_NE_NAMESPACE + ANGLE_RIGHT + NEW_LINE);
request.append(buildStartTag(PARTICIPANT_LIST));
for (count = ZERO; count < onuList.length; count++) {
String[] onuId = onuList[count].split(HYPHEN);
if (onuId.length != TWO) {
log.error("Invalid ONU identifier");
return null;
}
try {
int pon;
pon = Integer.parseInt(onuId[FIRST_PART]);
if (pon <= ZERO) {
log.error("Invalid integer for ponlink-id:{}", onuId[FIRST_PART]);
return null;
}
int onu;
onu = Integer.parseInt(onuId[SECOND_PART]);
if (onu <= ZERO) {
log.error("Invalid integer for onu-id:{}", onuId[SECOND_PART]);
return null;
}
} catch (NumberFormatException e) {
log.error("Non-number input");
return null;
}
request.append(buildStartTag(MEMBER)).append(buildStartTag(PONLINK_ID)).append(onuId[FIRST_PART]).append(buildEndTag(PONLINK_ID)).append(buildStartTag(ONU_ID)).append(onuId[SECOND_PART]).append(buildEndTag(ONU_ID)).append(buildEndTag(MEMBER));
}
request.append(buildEndTag(PARTICIPANT_LIST)).append(buildStartTag(IMAGE_NAME)).append(data[FIRST_PART]).append(buildEndTag(IMAGE_NAME));
if (data.length == THREE) {
request.append(buildStartTag(REBOOT_MODE)).append(data[THIRD_PART]).append(buildEndTag(REBOOT_MODE));
}
request.append(buildEndTag(ONDEMAND_FIRMWARE_UPGRADE));
reply = controller.getDevicesMap().get(ncDeviceId).getSession().doWrappedRpc(request.toString());
} catch (NetconfException e) {
log.error("Cannot communicate to device {} exception {}", ncDeviceId, e);
}
return reply;
}
Aggregations